Please enable JavaScript.
Coggle requires JavaScript to display documents.
JavaScript Language (OPERATORS (ASSIGNMENT (x = y //Assignment, x += y…
JavaScript Language
OPERATORS
Arithmetic
-
-
DIVISION (/)
-
-
If you divide by zero, JavaScript does not raise any error but returns the Infinity
REMAINDER (%)
-
-
reminder by zero is always NaN, a special value that means “Not a Number”:
-
-
UNARY
INCREMENT (++)
if put before the number, it returns the value incremented.
If put after the number, it returns the original value, then increments it.
-
-
DECREMENT (–)
Works like the increment operator, except it decrements the value.
-
-
-
UNARY PLUS (+)
If the operand is not a number, it tries to convert it. Otherwise if the operand is already a number, it does nothing.
-
PRECEDENCE RULES
The precedence of operators determines the order they are applied when evaluating an expression. You can override operator precedence by using parentheses.
Comparison
-
-
Strict equal (===) Returns true if the operands are equal and of the same type. See also Object.is and sameness in JS.
Strict not equal (!==) Returns true if the operands are of the same type but not equal, or are of different type.
-
Greater than or equal (>=) Returns true if the left operand is greater than or equal to the right operand.
-
Less than or equal (<=) Returns true if the left operand is less than or equal to the right operand.
LOGICAL
Logical OR (||) expr1 || expr2 Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values, || returns true if either operand is true; if both are false, returns false.
Logical AND (&&) expr1 && expr2 Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.
Logical NOT (!) !expr Returns false if its single operand that can be converted to true; otherwise, returns true.
BITWISE
Bitwise AND a & b Returns a one in each bit position for which the corresponding bits of both operands are ones.
Bitwise OR a | b Returns a zero in each bit position for which the corresponding bits of both operands are zeros.
Bitwise XOR a ^ b Returns a zero in each bit position for which the corresponding bits are the same.
[Returns a one in each bit position for which the corresponding bits are different.]
-
Left shift a << b Shifts a in binary representation b bits to the left, shifting in zeros from the right.
Sign-propagating right shift a >> b Shifts a in binary representation b bits to the right, discarding bits shifted off.
Zero-fill right shift a >>> b Shifts a in binary representation b bits to the right, discarding bits shifted off, and shifting in zeros from the left.
-
-
-
-
-
Spread operator
var lyrics = ['head', ...parts, 'and', 'toes'];
FUNCTIONS
A function is a block of code, self contained, that can be defined once and run any times you want.
can optionally accept parameters, and returns one value
Functions in JavaScript are objects, a special kind of objects: function objects. Their superpower lies in the fact that they can be invoked.
functions are said to be first class functions because they can be assigned to a value, and they can be passed as arguments and used as a return value.
-
PARAMETERS
-
-
-
can wrap all your arguments in an array, and use the spread operator when calling
RETURN VALUES
Every function returns a value, which by default is undefined
is terminated when its lines of code end, or when the execution flow finds a return keyword
-
-
NESTED FUNCTIONS
-
nested function is scoped to the outside function, and cannot be called from the outside
OBJECT METHODS
as object properties, functions are called methods
ARROW FUNCTIONS
this in the arrow function refers to the enclosing function context #
-
SYNTAX
-
const myFunction = (param1, param2) => doSomething(param1, param2)
-
-
IIFE, IMMEDIATELY INVOCATED FUNCTION EXPRESSIONS
-
-
-
-
-
(/* function */)()
wrapping parentheses are actually what make our function, internally, be considered an expression
-
-
-
-
Expressions
-
-
Primary
variable references, literals and constants
-
-
-
-
-
-
-
-
-
-
-
-
-
OBJECT CREATION
-
-
new MyRectangle('name', 2, {a: 4})
-
function(a, b) { return a * b }
-
-
-
-
Lexical Structure
-
-
-
-
-
Literals
-
-
-
-
{color: 'red', shape: 'Rectangle'} //object
-
-
VARIABLES
A variable is a literal assigned to an identifier, so you can reference and use it later in the program.
-
-
-
VAR
-
-
can redeclare the variable many times, overriding it
-
-
-
LET
-
Its scope is limited to the block, statement or expression where it’s defined, and all the contained inner blocks.
-
-
CONST
A once a const is initialized, its value can never be changed again, and it can’t be reassigned to a different value.
-
-
const does not provide immutability, just makes sure that the reference can’t be changed.
const has block scope, same as let
.
-
THIS
Outside any object, this in strict mode is always undefined
-
-
TYPES
PRIMITIVE
-
Strings
-
-
-
-
can be joined using the +
#
-
BOOLEANS
-
comparision operations == === < > (and so on) return either one or the other #
if, while statements and other control structures use booleans to determine the flow of the program.
-
special types:
-
UNDEFINED
-
It’s commonly returned by functions with no return value. When a function accepts a parameter but that’s not set by the caller, it’s undefined.
-
-
-