Don’t like reading? Watch the Part 1 in video instead!
Programming languages that allow such things are called “dynamically typed”, meaning that there are data types, but variables are not bound to any of them.
Strings are written with quotes. You can use single or double quotes. You can use quotes inside a string, as long as they don’t match the quotes surrounding the string.
For example: A substring of the original by picking individual letters or using String.substr(). A concatenation of two strings using the concatenation operator (+) or String.concat().
Don’t like reading? Watch the Part 2 in video instead!
Extra large or extra small numbers can be written with scientific (exponential) notation.
The number type represents both integer and floating point numbers. There are many operations for numbers, e.g. multiplication *, division /, addition +, subtraction -, and so on.
Besides regular numbers, there are so-called “special numeric values” which also belong to this data type: Infinity, -Infinity and NaN.
The script will never stop with a fatal error (“die”). At worst, we’ll get NaN as the result.
That’s about 16 decimal digits, so for most purposes the limitation isn’t a problem, but sometimes we need really big numbers, e.g. for cryptography or microsecond-precision timestamps.
With BigInts, you can safely store and operate on large integers even beyond the safe integer limit for Numbers.
You can use the operators +, *, -, **, and % with BigInts—just like with Numbers. A BigInt is not strictly equal to a Number, but it is loosely so. A BigInt behaves like a Number in cases where it is converted to Boolean: if, ||, &&, Boolean, !.
BigInts cannot be operated on interchangeably with Numbers. Instead a TypeError will be thrown.
Booleans can only have two values: true or false. Booleans are often used in conditional testing.
With the object literal syntax, a limited set of properties are initialized; then properties can be added and removed.
Property values can be values of any type, including other objects, which enables building complex data structures.
Properties are identified using key values. A key value is either a String or a Symbol value.
There are two types of object properties which have certain attributes: The data property and the accessor property.
Data property Associates a key with a value and Accessor property Associates a key with one of two accessor functions (get and set) to retrieve or store a value.
Keys are strings (or Symbols), and values can be anything. This makes objects a natural fit for hashmaps.
Any variable can be emptied, by setting the value to undefined. The type will also be undefined.
An empty value has nothing to do with undefined. An empty string has both a legal value and a type.
undefined and null are equal in value but different in type.
Don’t like reading? Watch the Part 3 in video instead!
A primitive data value is a single simple data value with no additional properties and methods.
The typeof operator can return one of these primitive types: string, number, boolean, undefined.
Functions are regular objects with the additional capability of being callable.
Arrays are regular objects for which there is a particular relationship between integer-key-ed properties and the length property.
The only valuable purpose of typeof operator usage is checking the Data Type. If we wish to check any Structural Type derived from Object it is pointless to use typeof for that, as we will always receive “object”. The indeed proper way to check what sort of Object we are using is to use an instanceof keyword. But even in that case there might be misconceptions.
A Symbol is a unique and immutable primitive value and may be used as the key of an Object property.
In some programming languages, Symbols are called “atoms”.
New data structures
These data structures, introduced in ECMAScript Edition 6, take object references as keys.
Set and WeakSet represent a set of objects, while Map and WeakMap associate a value to an object.
The difference between Maps and WeakMaps is that in the former, object keys can be enumerated over. This allows garbage collection optimizations in the latter case.
Maps and WeakMaps make it easy to privately bind data to an object.