Place with explanations for each buzzword in the JS world.π
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
JS Core:
A:
Array
Basic composing data type. More on in Complete guide to Arrays
.
Abstract Equality
Comparison operator (x == y
, where x and y are values, produces true
or false
).
π rules table ...
Condition | Return | Example | Result |
---|---|---|---|
1. type(x) equals to type(y) | x === y | {} == {} | false |
- | [] == {} | false | |
- | [] == [] | false | |
2. null with undefined | true | null == undefined | true |
- | undefined == null | true | |
3. Number with String | x == toNumber(y) | 4 == '3' | false |
- | '4' == 3 | false | |
4. x is Boolean | toNumber(x) == y | true == 1 | true |
- | true == 2 | false | |
- | 2 == true | false | |
5. Str/Num/Symb with Obj | x == toPrimitive(x) | 1 == {} | false |
- | [] == 0 | true | |
- | {} == '[object Object]' | true |
More on in ECMA-262
7.2.12 Abstract Equality Comparison
.
AJAX
Arrow Functions
C:
Call stack
A stack data structure that keeps information about active function call.
Cast
Explicit conversion a value from one data type
to another: String(42)
.
Coercion
Implicit conversion a value from one data type
to another: 42 + ''
. Related terms: weak typing
.
π coercion rules ...
Operator +
becomes a concatenation in the follows cases:
String
withString
:
'1' + '1' // '11'
String
with any other type (exceptsymbol
):
1 + '2' // '12'
'2' + 1 // '21'
true + '_foo' // 'true_foo'
Object
with any other type (exceptsymbol
):
[] + {} // '[object Object]'
[] + true // 'true'
[1, 2] + [3] // '1,23'
// !gotchas, here {} is empty block instead of object
{} + [] // 0
In other cases +
returns number
:
2 + true // 3
true + true // 2
Operators -
, *
, /
always return number
:
'1' * '2' // 2
[2] * [3] // 6
[2] * true // 6
true * false // 0
'foo' * true // NaN
5 * { valueOf: () => 5 } // 25
5 * { toString: () => '7' } // 35
5 * { valueOf: () => 5, toString: () => '7' } // 25
D:
Data type
Abstraction that has a bounded set of available values and operations that can be performed on these values.
Dynamic typing
Means that variable can represents any value of any type. Related terms: Duck typing
, Weak typing
.
Duck typing
General term for βtype checksβ that make assumptions about a valueβs βtypeβ
based on its shape (what properties are present).
βIf it looks like a duck, and quacks like a duck, it must be a duckβ. Related terms: Dynamic typing
, Weak typing
.
E:
Event loop
The mechanism that performs moving functions from the event queue
to call stack
when it becomes empty. Read more about Event loop in JS
.
F:
First-class Function
Functions are treated as values β you can assign a function into a variable, pass it around etc. Related terms: higher-order function
.
G:
Generator
Function that can be paused in mid-completion with saving inner state. Related terms: iterator
.
π example of Generator ...
function *foo(a) {
const sum = a + (yield)
return sum
}
const it = foo(1)
// start
it.next()
// pass value instead of yield
const res = it.next(2) // { value: 3, done: true }
res.value // 3
π getting data from Generator ...
function *foo(a) {
const sum = a + (yield 'bar')
return sum
}
const it = foo(1)
// start
const passedValue = it.next() // { value: 'bar', done: false }
// pass value instead of yield
const res = it.next(2) // { value: 3, done: true }
π generators for handling async code ...
function *main() {
try {
const data = yield fetch('foo.bar')
console.log(data)
}
catch (err) {
console.error(err)
}
}
const it = main()
const promise = it.next().value
promise
.then((data) => it.next(data))
.catch((err) => it.throw(err))
H:
Higher-order Function
A function that takes a function as an argument, or returns a function. Related terms: first-class function
.
Hoisting
Moving all declarations to their respective scopes.
I:
Introspection
The ability of a program to examine the type or properties of an object at runtime. Read more in the Complete Guide to Objects
.
Iterable
An object
that contains an iterator
that can iterate over its values.
π example of Iterable ...
const iterable = {
[Symbol.iterator]() {
let counter = 0
const iterator = {
next() {
return {
value: counter++,
done: counter > 5,
}
},
}
return iterator
}
}
for (const step of iterable) {
console.log(step)
}
// 0
// 1
// ...
π example of async Iterable ...
const iterable = {
[Symbol.asyncIterator]() {
let counter = 0
const iterator = {
async next() {
return {
value: counter++,
done: counter > 5,
}
},
}
return iterator
}
}
;(async () => {
for await (const step of iterable) {
console.log(step)
}
})()
// 0
// ...
π example of Iterable & Iterator at the same time ...
let counter = 0
const iterable = {
[Symbol.iterator]() { return this },
next: () => {
return {
done: counter > 5,
value: counter++,
}
}
}
console.log(...iterable) // 0 1 2 3 4 5
Iterator
An object
that has the next(..)
method on its interface. Related terms: generator
.
π example of Iterator ...
const iterator = {
counter: 0,
next() {
return {
value: this.counter++,
done: this.counter > 5,
}
},
}
const step1 = iterator.next() // { value: 0, done: false }
const step2 = iterator.next() // { value: 1, done: false }
π example of async Iterator ...
const asyncIterator = {
counter: 0,
async next() {
return {
value: this.counter++,
done: this.counter > 5,
}
},
}
const step1 = asyncIterator.next() // Promise
const step2 = asyncIterator.next() // Promise
J:
JSON
JSON-safe
JSON-safe values consist of values that can be represented as JSON.
Not JSON-safe: undefined
s, function
s, symbol
s, object
s with circular references, Date
s, Infinity
, RegExp
s, Map
s, Set
s, Blob
s, FileList
s, sparse Array
s, Typed Array
s or other complex types.
L:
Lexical scope
Scope
that defined during the lexing time.
Let
Localstorage
M:
Map
N:
Number
Numeric data type, that represents both integer and fractional numbers. Read more in the Complete Guide to Numbers
.
O:
Object
Basic data type. More on in Complete Guide to Objects
.
P:
Promise
Proxy
ES6 feature that allows boxing software component with an interception of component handlers, like getting/setting/deleting/enumeration object properties, applying arguments to functions, etc.
R:
Reflect
Reflection
The ability for a program to manipulate the values, meta-data, properties and/or functions of an object at runtime.
Regular Expressions
S:
Scope
The accessibility of objects (variables/functions) in some part of your program.
Set
Symbol
New data type offered by ES6, a unique identifier for special object properties.
Stack frame
Block of the stack
corresponds to some function call that keeps relative information about this call (local variables, parameters, a location where to be returned).
T:
TCO
Tail Call Optimization. Read more about Tail call optimization in JavaScript
.
W:
Weak typing
Means that compiler can use coercion
. Related terms: dynamic typing
, duck typing
.