Closures in javasctipt

Home » Tutorials » JavaScript » 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

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This