immutability - Correct way to permanently alter a JavaScript string -
in ruby, if want modify string , have change original string, can use !
bang character.
string = "hello" string.capitalize! > "hello" string > "hello"
in javascript, can't find equivalence. modifying string uppercase
instance returns original string after first instance.
var string = "hello"; string.touppercase(); > "hello" string > "hello"
i know can save variable such
var uppercasestring = string.touppercase();
but seems inefficient , undesirable purposes.
i know must obvious, missing?
the return value of touppercase
new string capitalized. if want keep , throw away original, use this:
string = string.touppercase();
btw, when entering js statements on command line of node.js , similar environments, prints result of evaluating each expression, why see uppercase version if type
string.touppercase();
as have deduced has no effect on original string.
Comments
Post a Comment