- attribute : It called attribute within object
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var MYAPP={}//MYAPP is a global variable
MYAPP.calculator={ //calculator is an attribute
'left':null,//null means undefined the value
'right':null
}
MYAPP.coordinate={
'left':null,
'right':null
}
MYAPP.calculator.left=10;
MYAPP.calculator.right=20;
function sum(){
return MYAPP.calculator.left+MYAPP.calculator.right;
}
document.write(sum());
(function(){ //anonymous function
var MYAPP={}//MYAPP is a local variable
MYAPP.calculator={
'left':null,
'right':null
}
MYAPP.coordinate={
'left':null,
'right':null
}
MYAPP.calculator.left=10;
MYAPP.calculator.right=20;
function sum(){
return MYAPP.calculator.left+MYAPP.calculator.right;
}
document.write(sum());
}())
var i = 5;
function a(){
var i=10;
b();
}
function b(){
document.write(i);//in this case, i returns 5 because it used when it defined
}
</script>
</body>
</html>