Chapter 15. JavaScript 4: Objects and Arrays Table of Contents


Copying primitive type variables



Download 0.78 Mb.
View original pdf
Page13/16
Date04.04.2022
Size0.78 Mb.
#58550
1   ...   8   9   10   11   12   13   14   15   16
chp15
15.2.10 Copying primitive type variables
With primitive type variables it is straightforward to copy and change values. Consider the following code var name = "ibrahim"; var name = "james"; Initially the memory looks as follows
Memory Location Value name
"Ibrahim" name James" Then if we execute the following lines name = name name = "fred"; the values in memory will be
Memory Location Value name James" name
"fred" What is happening is that when one variable is assigned the value of a second, a copy of the second variable's value is placed into the location in memory for the first — so a copy of the value "james" from name was copied into the location for name.

Download 0.78 Mb.

Share with your friends:
1   ...   8   9   10   11   12   13   14   15   16




The database is protected by copyright ©ininet.org 2024
send message

    Main page