The scope of var
is wrong
Never use var
to declare variables, use let
instead.
==
is conversion and comparison
What you really need is ===
, which is similar to comparing two interface{}.
===
is shallow
{a:1}==={a:1}
is false
, while Go struct with string are compared by contents (but not for slice).
Also this affects map key comparison. So object key is not so useful in JS as struct key in Go. The equality test is always on the references rather than the contents.
const
works for objects, but the contents are modifiable
Single and double quotes are the same
Back quotes are like text/template
Escapes also works in back quotes and more template related features.
Switch cases fall through by default
Access undeclared object property returns undefined
Trying to access undeclared variables throws an exception but accessing undeclared
object properties return a value called undefined
.
Use 'property' in obj
to check if a property is declared or not.
Only float64 is supported
Object is like map[string]interface{}
Array is like map[int]interface{}
Map is like map[interface{}]interface{}
for...in
traverses properties recursively
for...of
is like for...range
in Go
object.constructor.prototype
console.log({}.constructor === {}['__proto__'].constructor);
console.log({}.constructor.prototype === {}['__proto__']);
Promise can be chained and composed
It is quite impressive how JS do concurrency differently and efficiently.
Promise.then(onFulfilled)
where onFufilled
can return another Promise.
Promise.all([func1(), func2(), func3()])
.then(([result1, result2, result3]) => { /* use result1, result2 and result3 */ });
Computed property name
{
[prop]: 42,
}
There are two types of generator method syntax
{
*gen() {
}
}
{
gen: function*() {
}
}