Skip to content

JS Knowledge

Data Structure

The built-in shift() is not the most efficient method. Sometimes you just need a pointer and clean up the memory periodically.

Object

Could use this to implement one simple Set. (Also a built-in Set in ES6)

.hasOwnProperty("x") checks if this object has a certain property x

delete obj["x"]/ obj.x deletes this property & data

Function

this & arrowfunction

太长不看版:js function中的this与这个function本身有关,即使它被包在object内;然而arrow function的this由外部决定,所以这里要用arrow functinon……之前一定是在哪里看到这个知识点,然而忘了。 补充:可以使用bind函数将某个函数中的this与某个对象绑定

Declaration

for...in or for...of?

var or let?

var is function scoped while let is block scoped

so when you declar var in an if statement, you could get this variable even outside of the block(but not outside of this function), but let cannot.

also, var got decleared at the top of each function(even the value assignment is still given at the same line)

Value & Type

check null

null == null // true
null === null // true
null == undefined // true

When using double equal to check, the value might be undefined or null, so it is better to use triple equal when you really need null.

However, in generall we don't really need to distinct them, as they are both falsy values, a more common and easier way is to check its value is false or not, see this article