javascript-basics

This is a Javascript basics as a tags, summarized from Speaking Javascript Book.

 

Primitive:: Numbers, Boolean, String, Undefined & Null
Objects:: plain object, array, regular expression
Primitive :: (immutable) Properties can’t be changed, added, or removed
Objects :: (Mutable) change, add, and remove properties
undefined means “no value.” Uninitialized variables are undefined
null means “no object”
undefined and null are considered false
false, 0, NaN, and ” are also considered false
Values:: typeof is mainly used for primitive values, while instanceof is used for objects
typeof null returning ‘object’ is a bug that can’t be fixed, because it would break existing code. It does not mean that null is an object.
Logical Operators:: if the first operand suffices for determining the result, the second operand is not evaluated. EX:: false && foo(), true || foo()
All numbers in JavaScript are floating-point
Convert to number: +value
A function expression produces a value and can thus be used to directly pass functions as arguments to other functions:
Function Declarations Are Hoisted :: EX:
function foo() {
bar(); // OK, bar is hoisted
function bar() {

}
}
arguments is not an array, it is only array-like
The IIFE Pattern :: function in a block-like manner
bind() :: creates a new function whose this always has the given value, EX:
var func2 = jane.describe.bind(jane);
func2()
method VS function :: FUN called by name while Meth called by name associated with an object
Every function has its own special variable this
you can’t access the method’s this from the function so you have to define this
Constructors: Factories for Objects
map() creates a new array by applying a function to each element of an existing array
Regular Expression:: Method test(): Is There a Match?
Regular Expression:: Method exec(): Match and Capture Groups :: return array

Regular Expression:: Method replace(): Search and Replace

Leave a Comment