Javascript!


Lexical Structure


Literals:


Variables.

When do you mutate, when do you not (hint: NEVER MUTATE ANYTHING)


Variable Initialization

Using nothing: In javascript, it is possible to assign a value to a variable.


Variable Initialization

var: Variables can be declared with var.


Variable Initialization

let: A newer ES6 variable that acts almost the exact same as var:


Variable Initialization

const: Once initialized, a const's value can never be changed.


Variables: Scoping



Types:

Primitives:


Primitives - Numbers:

Number encompasses both floating points and integers


Primitives - String:

A sequence of characters. Strings can be enclosed in both single and double quotes, as well as ticks. As of ES6, template strings now exist (those with the ticks). Template stings allow for mid-string variable interpolation


Primitives - Boolean:

Booleans are true and false.


Example!


Types:

Object Types

 


Objects:

An object is a datatype that contains key-value pairings.

To access these elements, you need only to use dot notation:


Classes:


Exceptions

Just like other languages try catch blocks exist to handle errors gracefully.


Arrays:

Arrays are lists.


Functions!


Functions - Syntax

Function Declarations (older):


Functions - Syntax

Function Expressions: assignment to a variable


Functions - Syntax

Named Function Expressions: (these play well with stack traces)


Functions - Syntax

Arrow Functions: As of ES6, arrow functions have been introduced.


Arrow functions allow for an implicit return for one line statements! This means that you don't have to write return variableName in specific instances.


When implicitly returning an object from an arrow function, the object needs to be wrapped in parentheses:


Functions - Parameters:


Functions - Parameters:


Functions - Parameters:


Functions - Parameters:


Return Values:


Return Values: Destructuring Arrays


Return Values: Destructuring Objects


Function Nesting:


Function Nesting:


Functions in Objects:


Functions in Objects:


Functions in Objects


Functions in Objects


Functions in Objects


First Class Functions


First Class Functions : Passing Functions


First Class Functions : Passing Functions


First Class Functions : Returning Functions


First Class Functions : Returning Functions


First Class Functions : Returning Functions


First Class Functions : Returning Functions


Closures

When a function is run, it's executed within the scope of where it was defined, and not where it was run. (This ends up being incredibly helpful in the world of React):