In this post, I’ll share the basic syntax that I used during the my work. For the demonstration purpose, the Chrome DevTool (v67.0) is used.
var statement declares a variable, optionally initializing
it to a value:
const declaration creates a read-only reference to a
value. The value of a constant cannot change through re-assignment, and it
cannot be redeclared:
Define a new class. You can 1) define input parameters for constructor;
2) define a computed variable in constructor; 3) define an instance method such
toEmail(); In an instance method, when referencing an instance
variable, you must use the keyword
this — it cannot be omitted.
There can be only one method called
constructor in a class. Having more
than one occurence will throw a
Instantiate a class instance.
Query instance members. Instance variables are accessible using the following
syntax. Method can be called in similar way, however, don’t forget the
==). The equality operator converts the operands if they are not
of the same type, then applies strict comparison. If both operands are objects,
refer to the same object in memory.
Identity / strict equality (
===). The identity operator returns true if
the operands are strictly equal with no type conversion.
Create an array.
Iterate an array. There’re many ways to achieve this:
- A simple loop
- A for…of loop
Add an element to array.
Remove an element from array. Note that we can only remove the last one:
Function map(). Use
map() to create a new array from the
Sorting. Sort by natural order, by numeric value, by string:
JSON.stringify() allows you to serialize an instance to string.
JSON.parse() allows you to deserialize a string into an instance.