Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.log(typeof name); // undefined
- var name = "John";
- console.log(typeof name); // ReferenceError
- let name = "John";
- console.log(typeof name); // ReferenceError
- const name = "John";
- x = "global";
- // function scope:
- (function() {
- x; // not "global"
- var/let/… x;
- }());
- // block scope (not for `var`s):
- {
- x; // not "global"
- let/const/… x;
- }
- x = y = "global";
- (function() {
- x; // undefined
- y; // Reference error: y is not defined
- var x = "local";
- let y = "local";
- }());
- function doSomething(arr){
- //i is known here but undefined
- //j is not known here
- console.log(i);
- console.log(j);
- for(var i=0; i<arr.length; i++){
- //i is known here
- }
- //i is known here
- //j is not known here
- console.log(i);
- console.log(j);
- for(let j=0; j<arr.length; j++){
- //j is known here
- }
- //i is known here
- //j is not known here
- console.log(i);
- console.log(j);
- }
- doSomething(["Thalaivar", "Vinoth", "Kabali", "Dinesh"]);
- for(var i=0; i<5; i++){
- setTimeout(function(){
- console.log(i);
- },1000)
- }
- for(let i=0; i<5; i++){
- setTimeout(function(){
- console.log(i);
- },1000)
- }
- const foo = {};
- foo.bar = 42;
- console.log(foo.bar); //works
- const name = []
- name.push("Vinoth");
- console.log(name); //works
- const age = 100;
- age = 20; //Throws Uncaught TypeError: Assignment to constant variable.
- console.log(age);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement