Skip to content

Instantly share code, notes, and snippets.

View djD-REK's full-sized avatar
🌞
Full-Stack JavaScript Developer & Doctor of Physical Therapy 🌞

Dr. Derek Austin djD-REK

🌞
Full-Stack JavaScript Developer & Doctor of Physical Therapy 🌞
View GitHub Profile
(employeeBonus>500) ? console.log("πŸ₯³") : console.log("πŸ™‚") // πŸ₯³
if (employeeBonus>500)
{ console.log("πŸ₯³") }
else
{ console.log("πŸ™‚") } // πŸ₯³
let monthProfitOrLoss = (profit > costs) ? "Profit" : "Loss"
console.log(`${monthProfitOrLoss} last month`) // Profit last month
let views = 10000
`${views} views` === views + " views" // true
`${views} views` === "".concat(views).concat(" views") // true
typeof window // "object"
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
"".length === String("").length // true
// "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
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:
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: