
January 2nd, 2013, 10:24 AM
|
 |
JavaScript is not spelt java
|
|
Join Date: Feb 2011
Location: Landan, England
|
|
Code:
var myvar = "hello, world!";
myvar = "changed!";
I know it seems that you are changing myvar but, technically, you are not. The 2nd line creates a new string that myvar now points to. The previous string "hello, world!" still exists (unaltered) in the computers' memory - but it's of no use as nothing points to it. (It will be removed from memory later by a process called garbage collection.)
Similarly,
Code:
var myvar = "Hello World!";
myvar = myvar + " Yo!";
does not modify myvar; the 2nd line (again) creates a new string. This is why string operations can be expensive.
__________________
"The mysql extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used." the docs
|