Javascript

"use strict"; at the top of files will prompt new compliers to throw more errors like for using undefined variables

Objects and arrays passed by reference

There are packages that work just in the browser, just in react, just for gatsby, or just for node

Control

isMember ? "$2.00" : "$10.00"

if (c) {s} else if (c) {s} else {s}
for (let i = 0; i < cars.length; i++) { 
    text += cars[i] + "<br>";
}

switch(expression) {
    case x:
        code block
        break;
    case y:
        code block
        break;
    default:
        code block
}

Equality

=== is strict equality with type and strict

== uses type coercion

Type Conversion

Find type with typeof(var)

Random Integer

Math.random gives number between 0(inclusive) and 1(exclusive).

Why Javascript Sucks

Can use a variable before it is initalized with no error

Additionally, some array methods cannot find NaN, while others can.

Last updated