Created
December 10, 2017 21:07
-
-
Save yogain123/6374decfc71d648eeb3c4a4052a9789c to your computer and use it in GitHub Desktop.
Mordern JavaScript
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
hola |
Prototype
class Hola{
constructor(){
this.name="yogendra";
console.log(this);
}
static div(){
console.log("div");
}
sum(){
console.log("sum");
}
}
const h = new Hola();
console.log(Object.getPrototypeOf(h)) // {constructor: ƒ, sum: ƒ}
console.log(h.__proto__) // {constructor: ƒ, sum: ƒ}
console.log(Hola.prototype); // {constructor: ƒ, sum: ƒ}
Array.at()
Get the value at that position -> index passed
const arr = ["jack","yogi","abc"]
console.log(arr.at(0)) // "jack"
console.log(arr.at(-1)) // "abc"
This keyword
Akshay -> https://www.youtube.com/watch?v=9T4z98JcHR0&list=PLlasXeu85E9eWOpw9jxHOQyGMRiBZ60aX&index=9
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output
In the following code, I expected both a and b to be 3. However, a is undefined and b is 3. Why?
(function(){
var a = b = 3;
})();
console.log(typeof a);//"undefined"
console.log(b);//3
Actually it is
b = 3 is an assignment without a declaration. Since there is no b in the current execution context (the IIFE), JavaScript engine looks for b in the outer lexical environment. In this case, the outer environment is the global execution context.
Since b is not found in the global execution context either, and assuming non-strict mode, JavaScript implicitly creates b as a property of the global object (e.g., window.b in browsers). This makes b a global variable.