Closures in javasctipt
In one of the last lesson I was recieved the comment to make tutorial about closures in javascript. This lesson dedicated to closures
Code lesson
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
/*console.log(window);
var num = 5;*/
/*var c = 10;
function test() {
alert(c);
}
console.log(test);
test = null;
console.log(test);
test();*/
function sum(x,y) {
var res = function() {
alert(x+y);
}
return res;
}
var d = sum(3,5);
//d();
sum = null;
console.log(sum);
d();
</script>
</body>
</html>
0 Comments