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
if (a) { | |
//...a | |
} else if (b) { | |
//...b | |
} else { | |
//...c | |
} | |
//...is actually: |
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
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence | |
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
//https://github.com/getify/You-Dont-Know-JS/blob/master/types%20&%20grammar/ch5.md#automatic-semicolons | |
"It's important to note that ASI will only take effect in the presence of a new-line (aka line-break). | |
Semicolons are not inserted in the middle of a line. | |
Basically, if the JS parser parses a line where a parser error would occur (a missing expected ;), | |
and it can reasonably insert one, it does so. What's reasonable for insertion? | |
Only if there's nothing but whitespace and/or comments between the end of some statement and that | |
line's new-line/line break." |
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
https://github.com/getify/You-Dont-Know-JS/blob/master/types%20&%20grammar/apA.md#appendix-a-mixed-environment-javascript | |
Host Objects | |
Global DOM Variables | |
what may be lesser common knowledge is that (because of legacy browser behavior) | |
creating DOM elements with id attributes creates global variables of those same names. | |
For example: |
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
https://github.com/getify/You-Dont-Know-JS/blob/master/async%20&%20performance/ch1.md#async-console | |
there are some browsers and some conditions that console.log(..) | |
does not actually immediately output what it's given. | |
The main reason this may happen is because I/O is a very slow and blocking | |
part of many programs (not just JS). | |
So, it may be more performant (from the page/UI perspective) for a browser to | |
handle console I/O asynchronously in the background. |
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
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20&%20closures/ch4.md | |
"When you see var a = 2;, you probably think of that as one statement. | |
But JavaScript actually thinks of it as two statements: var a; and a = 2;. | |
The first statement, the declaration, is processed during the compilation phase. | |
The second statement, the assignment, is left in place for the execution phase." | |
- declaration comes before the assignment | |
- function declarations are hoisted, but function expression are not |
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
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20&%20closures/ch4.md#functions-first | |
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
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20&%20closures/ch5.md | |
Closure is when a function is able to remember and access its lexical scope even | |
when that function is executing outside its lexical scope. | |
function foo() { | |
var a = 2; | |
function bar() { | |
console.log( a ); // 2 |
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 a = 2; | |
function bar() { | |
console.log( a ); | |
} | |
return bar; | |
} |
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 year = new Date().getFullYear(); | |
var tenYears = []; | |
for (var i = 0; i < 10; i++) { | |
tenYears.push(year++); | |
} | |
console.log(tenYears); |
OlderNewer