Learning JavaScript in depth, this repository contains notes and code for the concepts that I find useful and insightful :)
In javascript, object by default are copied as a reference, i.e. only the
memory address is copied. To use deep copy, one can use loadash
_.cloneDeep()
.
It basically perform a dfs on the reachability graph, marking all possibe nodes reachable from the main node and deletes all the unmarked nodes.
This basic algorithm is done with some optimzations.
this
keywordthis
takes the shape of the context, in case of non-strict mode the browser’s
window
.
new
keywordExecute the function with prepended this = {}
and postpended return this
.
new.target
keywordThis is a special keyword, which contains the reference to the function called
with new
operator i.e. the body of the function. By default, it is
undefined
.
null
// the given function returns `null` if not found
let html = document.querySelector('.elem').innerHTML; // error if it's null
?.
The object returns undefined
if object?.
is used and object is either
undefined
or null
.
https://javascript.info/symbol
Primitive data types do not have methods as per say, but when one calls the
methods, there exist an object wrapper which is created for example String
for str
and provides the methods to mutate the underlying primitive data
type.