This file contains hidden or 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
(employeeBonus>500) ? console.log("π₯³") : console.log("π") // π₯³ |
This file contains hidden or 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 (employeeBonus>500) | |
{ console.log("π₯³") } | |
else | |
{ console.log("π") } // π₯³ |
This file contains hidden or 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
let monthProfitOrLoss = (profit > costs) ? "Profit" : "Loss" | |
console.log(`${monthProfitOrLoss} last month`) // Profit last month |
This file contains hidden or 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
let views = 10000 | |
`${views} views` === views + " views" // true | |
`${views} views` === "".concat(views).concat(" views") // true |
This file contains hidden or 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 window // "object" |
This file contains hidden or 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
const primitiveString = `Hello world!` // primitive type string | |
const wrappedString = new String(`Hello world!`) // wrapper object | |
console.log(typeof primitiveString) // "string" | |
console.log(typeof wrappedString) // "object" | |
console.log(primitiveString == wrappedString) // true | |
console.log(primitiveString === wrappedString) // false | |
const almostWrappedString = String(`Hello world!`) // wrapper called without new |
This file contains hidden or 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
"".length === String("").length // true |
This file contains hidden or 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
// "The following are confusing, dangerous, and wasteful. Avoid them." -MDN Docs | |
typeof new Boolean(false) === 'object'; // true | |
typeof new Number(37) === 'object'; // true | |
typeof new String(`Hello World!`) === 'object'; // true |
This file contains hidden or 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
const helloWorldObject = { hello: "world" } | |
console.log(typeof helloWorldObject) // 'object' | |
// use Array.isArray or Object.prototype.toString.call | |
// to differentiate regular objects from arrays | |
const fibonacciArray = [1, 1, 2, 3, 5, 8] | |
console.log(typeof fibonacciArray) // 'object' | |
console.log(Array.isArray(helloWorldObject)) // false | |
console.log(Array.isArray(fibonacciArray)) // true | |
// There is another helper function, though it is a bit long: |
This file contains hidden or 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
const mightBeNaN = NaN // NaN means "Not-a-Number" | |
// Anything compares false when compared to NaN: | |
console.log(37 === NaN) // false | |
console.log(mightBeNaN === NaN) // false | |
// NaN is the only value that does not equal itself: | |
console.log(mightBeNaN !== mightBeNaN) // true | |
// Creating an invalid Date results in the value NaN: |