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:
- Boolean – Boolean is a logical data type that can have only the
values true
or false
. 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.- 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. - Number – JS Number is a numeric data type. Integers, Floats, Doubles, or Bignums — all fall under Number
- BigInt – In JavaScript, BigInt 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. - String – In any computer programming language, a string is a sequence of characters used to represent text.
- 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.
A 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