In [3]:
// golbal define function alert
if((typeof alert) === 'undefined') {
global.alert = function(message) {
console.log(message);
}
}
function addTen(num) {
num += 10;
return num
}
function setName(obj) {
obj.name = "ZJ";
}
var count = 20;
var result = addTen(count);
alert(count);
alert(result);
var person = new Object();
setName(person);
alert(person.name);
Out[3]:
In [4]:
function setName(obj) {
obj.name = "ZJ";
obj = new Object();
obj.name = "newZJ";
}
var person = new Object();
setName(person);
alert(person.name);
Out[4]:
In [9]:
var s = "ZJ";
var b = true;
var i = 22;
var u;
var n = null;
var o = new Object();
alert(typeof s);
alert(typeof b);
alert(typeof i);
alert(typeof u);
alert(typeof n);
alert(typeof o);
alert("---");
colors = new Array();
pattern = new RegExp();
alert(person instanceof Object);
alert(typeof colors);
alert(colors instanceof Array);
alert(typeof pattern);
alert(pattern instanceof RegExp);
Out[9]:
In [12]:
if (true) {
var color = "blue";
}
alert(color);
function doSomething(i) {
;
}
for (var i=0; i < 10; i++) {
doSomething(i);
}
alert(i);
Out[12]:
In [13]:
function add(num1, num2) {
var sum = num1 + num2;
return sum;
}
var result = add(10, 20);
alert(sum);
In [14]:
function add(num1, num2) {
sum = num1 + num2;
return sum;
}
var result = add(10, 20);
alert(sum);
Out[14]:
In [15]:
var color = "blue";
function getColor() {
return color;
}
alert(getColor());
Out[15]:
In [16]:
var color = "blue";
function getColor() {
var color = "red";
return color;
}
alert(getColor());
Out[16]:
In [ ]: