This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(){ | |
console.log(this.bar); | |
} | |
var bar = "bar1"; | |
var o2 = { | |
bar:"bar2", | |
foo:foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(){ | |
var bar = "bar"; | |
for(let i = 0;i<bar.length;i++){ | |
console.log(bar.charAt(i)); | |
} | |
console.log(i) // Referece error | |
} | |
foo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = "foo"; | |
(function(){ // Can be named or anonymous | |
var foo= "bar"; | |
console.log(foo); // bar | |
})() | |
console.log(foo) // "foo" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = function bar(){ | |
var foo = "baz"; | |
console.log(foo); | |
function baz(foo){ | |
foo = "bam"; // Gets assigned to the local foo again | |
bam = "yay"; | |
} | |
baz(); // JS variatic functions. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var outerFunction = function(){ | |
if(true){ | |
var x = 5; | |
console.log(y); // ReferenceError: y not defined | |
} | |
var innerFunction = function() { | |
if(true){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lexical scope means compile time scope | |
var foo = "bar"; | |
function bar(){ | |
var foo = "baz"; //This is called shadowing. It will be in the local scope. | |
function baz(foo){ | |
foo = "bam"; // Gets assigned to the local foo again | |
bam = "yay"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var outerFunction = (function(){ | |
var publicInterface = { | |
inner : function(){ | |
console.log("Inner function"); | |
}, | |
anotherInner: function(){ | |
publicInterface.inner(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function secretPassword() { | |
var password = 'xh38sk'; | |
return { | |
guessPassword: function(guess) { | |
if (guess === password) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(var i = 1;i<=5;i++){ | |
(function(i){ | |
setTimeout(function(){ | |
console.log("value is : "+i); | |
},i*1000); | |
})(i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(var i = 1;i<=5;i++) | |
{ | |
setTimeout(function() | |
{ | |
console.log("value is : "+i); | |
},i*1000); | |
} |
NewerOlder