Basic Javascript Flashcards
arr.unshift(element1[, …[, elementN]])
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
arr.shift()
The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.
arr.push(element1[, …[, elementN]])
The push() method adds one or more elements to the end of an array and returns the new length of the array.
arr.pop()
The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
undefined
undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.
null
The value null represents the intentional absence of any object value. It is one of JavaScript’s primitive values and is treated as falsy for boolean operations.
falsy
A falsy (sometimes written falsey) value is a value that is considered false when encountered in a Boolean context.
if (false) if (null) if (undefined) if (0) if (-0) if (0n) if (NaN) if ("")
NaN
The initial value of NaN is Not-A-Number — the same as the value of Number.NaN. In modern browsers, NaN is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it.
parameter
Parameters are variables that act as placeholders for the values that are to be input to a function when it is called. When a function is defined, it is typically defined along with one or more parameters. The actual values that are input (or “passed”) into a function when it is called are known as arguments.
argument
An argument is a value (primitive or object) passed as input to a function.
differences between parameter & argument
Function parameters are the names listed in the function’s definition.
Function arguments are the real values passed to the function.
Parameters are initialized to the values of the arguments supplied.
let
The let statement declares a block scope local variable, optionally initializing it to a value.
const
Constants are block-scoped, much like variables defined using the let keyword. The value of a constant can’t be changed through reassignment, and it can’t be redeclared.
var
The var statement declares a function-scoped or globally-scoped variable, optionally initializing it to a value.
Math.random()
The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.
Math.random() * (max - min) + min;