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
"37" - 7 // 30 | |
"37" + 7 // "377" | |
"1.1" + "1.1" // "1.11.1" | |
(+"1.1") + (+"1.1") // 2.2 // Note: the parentheses are added for clarity, not required. |
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
typeof true // 'boolean' | |
typeof false // 'boolean' |
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
Boolean("") // false | |
Boolean(234) // true | |
Number("1e2") // 100 | |
String(true) // '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
true && true // true | |
true && false // false | |
true || false // true | |
false || false // 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
'0' == false // true | |
'0' == 0 // true | |
!!'0' // true | |
!!0 || !!'' || !!"" || !!null || !!undefined || !!false || !!NaN // 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
Number.prototype.times = function (fn) { | |
var n = this; | |
while (n > 0) { | |
fn(); | |
n--; | |
} | |
} |
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 courseInfo = { | |
title: 'Programming Languages', | |
number: 'HOUSECS 59.18', | |
instructors: [{ | |
name: 'Yang Su', | |
major: 'ECE/CS' | |
}, { | |
name: 'Kevin Gao', | |
major: 'ECE/CS' | |
}] |
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 a = { value: 1 }; | |
var b = a; | |
a.value = 2; | |
b.value // 2 | |
function subone(obj) { | |
obj.value -= 1; | |
} | |
subone(a); | |
a.value // 1 |
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 a = []; | |
a.length // 0 | |
a[100] // undefined | |
a = [1, 2, "three", "4", { value: 5}]; | |
a[4].value // 5 | |
a[10] = 1; | |
a.length // 11 | |
a[7] // undefined |
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
dontDoThis = 'ever !!!'; | |
var a; | |
if (a === undefined){ | |
console.log('a is ' + a); // 'a is undefined' | |
} | |
if (b) {} // this will generate an error "ReferenceError: b is not defined" | |
var n = null; | |
console.log(n * 32); // 0. Note: implicit type conversion |