Data Types in Javascript

8 Data types in total. Main Primitive and Object. There are 7 primitive data types and Object. Together they are 8.

Below is the list:

  1. Boolean – Boolean is a logical data type that can have only the values true or false.
  2. Null –  A null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. The meaning of a null reference varies among language implementations.
  3. Undefined – undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.
  4. Number – JS Number is a numeric data type. Integers, Floats, Doubles, or Bignums — all fall under Number
  5. BigInt – In JavaScriptBigInt is a numeric data type that can represent integers in the arbitrary precision format. In other programming languages different numeric types can exist, for examples: Integers, Floats, Doubles, or Bignums.
  6. String – In any computer programming language, a string is a sequence of characters used to represent text.
  7. Symbol – A value having the data type Symbol can be referred to as a “Symbol value”.  In a JavaScript run-time environment, a symbol value is created by invoking the function Symbol which dynamically produces an anonymous, unique value. A symbol may be used as an object property.

Symbol can have an optional description, but for debugging purposes only.

Symbol value represents a unique identifier. For example,

// here are two symbols with the same description,
let Sym1 = Symbol("Sym");
let Sym2 = Symbol("Sym");
  
console.log(Sym1 == Sym2); // returns "false"
// Symbols are guaranteed to be unique.
// Even if we create many symbols with the same description,
// they are different values.
let Sym = Symbol("Sym");

alert(Sym); // TypeError: Cannot convert a Symbol value to a string

let Sym = Symbol("Sym");

alert(Sym.toString()); // Symbol(Sym), now it works

Reference : Mozilla