<script>
/*
* Note:
* Literals are value types:
* - creates two literals
* - assigns second to first
* - changes first
* - second doesn't change
* - showvalue(obj) is defined in DemoScripts.js
*/
var s1 = "first string";
var s2 = "second string";
showvalue('s1 = \"' + s1 + '\"');
showvalue('s1 is ' + typeof (s1));
showvalue('s2 = \"' + s2 + '\"');
showvalue('s2 is ' + typeof (s1));
putline();
s2 = s1;
s1 = "new first string";
showvalue('s1 = \"' + s1 + '\"');
showvalue('s2 = \"' + s2 + '\"');
</script>
<script>
/*
* Note:
* Strings are immutable reference types:
* - creates two strings
* - assigns second to first
* - changes first
* - second doesn't change
* - showvalue(obj) is defined in DemoScripts.js
*/
var s1 = new String("first string");
var s2 = new String("second string");
showvalue('s1 = \"' + s1 + '\"');
showvalue('s1 is ' + typeof (s1));
showvalue('s2 = \"' + s2 + '\"');
showvalue('s2 is ' + typeof (s1));
putline();
s2 = s1;
s1 = new String("new first string");
showvalue('s1 = \"' + s1 + '\"');
showvalue('s2 = \"' + s2 + '\"');
</script>
<script>
/*
* Note:
* Objects are reference types:
* - creates two array Objects
* - assigns second to first
* - changes first
* - second changes
* - showvalue(obj) is defined in DemoScripts.js
*/
var a1 = ['one', 'two', 'three'];
var a2 = ['three', 'two', 'one'];
showvalue('a1 = ' + a1);
showvalue('a1 is ' + typeof (a1));
showvalue('a2 = ' + a2);
showvalue('a2 is ' + typeof (a2));
putline();
a2 = a1;
a1[0] = 'X';
showvalue('a1 = ' + a1);
showvalue('a2 = ' + a2);
</script>
<script>
/*
* Note:
* - show values and types for: int, double, boolean, array, object
*/
showvalue('-- integer --');
var n1 = 3;
showvalue('n1 = ' + n1);
showvalue('typeof(n1) = ' + typeof (n1));
var n2 = new Number(3);
showvalue('n2 = ' + n2);
showvalue('typeof(n2) = ' + typeof (n2));
putline();
showvalue('-- double --');
var n3 = 3.5;
showvalue('n3 = ' + n3);
showvalue('typeof(n3) = ' + typeof (n3));
var n4 = new Number(3.5);
showvalue('n4 = ' + n4);
showvalue('typeof(n4) = ' + typeof (n4));
putline();
showvalue('-- boolean --');
var n5 = true;
showvalue('n5 = ' + n5);
showvalue('typeof(n5) = ' + typeof (n5));
var n6 = new Boolean(false);
showvalue('n6 = ' + n6);
showvalue('typeof(n6) = ' + typeof (n6));
putline();
showvalue('-- array --');
var n7 = [1, 2, 3];
showvalue('n7 = ' + n7);
showvalue('typeof(n7) = ' + typeof (n7));
var n8 = new Array(4, 5, 6);
showvalue('n8 = ' + n8);
showvalue('typeof(n8) = ' + typeof (n8));
putline();
showvalue('-- object --');
var n9 = { name: 'Jim', location: 'Syracuse NY' } ;
showvalue('n9 = ' + n9);
showvalue('n9.name = ' + n9.name);
showvalue('n9.location = ' + n9.location);
showvalue('typeof(n9) = ' + typeof (n9));
var n10 = new Object({ university:'SU', department:'EECS'});
showvalue('n10 = ' + n10);
showvalue('n10.university = ' + n10.university);
showvalue('n10.department = ' + n10.department);
showvalue('typeof(n10) = ' + typeof (n10));
</script>