One of the big ideas of the core of any programming language, is the language ability to differentiate between different categories of data. So, for instance a language can differentiate between a number and a word. Or between a whole number and a fractional number. This varies between language to language. In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods.

There are 7 primitive data types: Number, String, BigInt, Boolean, Null, Undefined and Symbol.
We are going to do a quick overview of all.

// Numbers

Example:

10
4.5
-10

We have 3 numbers here. A whole number 10, a fractional or decimal number 4.5 and a negative number -10. We chose this numbers to show you that JavaScript doesn’t care if a number is whole or fractional or negative. Other languages do differentiate but JavaScript doesn’t.

// Strings

Example :

“Hello World”
“45”

The next data type that we have are strings. Strings are basically text. The important thing is that they are inside quotes. As we can
see in the example we have Hello World inside a quote. That is one string, even though is multiple words. Same as the second
example, we have a number 45 but inside quotes so its actually considered a string.

// Bigint

The BigInt data type aims to enable JavaScript programmers to represent integer values larger than the range supported by the Number data type. The ability to represent integers with arbitrary precision is particularly important when performing mathematical operations on large integers. With BigInt, integer overflow will no longer be an issue. A BigInt is created by appending n to the end of an integer or by calling the constructor.

// Boolean

Booleans have only two options, they are ether true or false. There is no quotes no numbers just the word true or the word false.

1>2 (one is bigger than two) // false
1<2 (one is smaller than two) // true

// Null and Undefined

Null: This data type represents the intentional absence of a value, and is represented by the keyword null (without quotes).

Undefined: This data type is denoted by the keyword undefined (without quotes). It also represents the absence of a value though it has a different use than null. For example if we declare a variable (var age;) but not initialize to a value it is consider undifined.

// Symbol

Symbols, the newest JavaScript primitive. Symbols are completely unique identifiers. Just like their primitive counterparts (Number, String, Boolean), they can be created using the factory function Symbol() which returns a Symbol.

const mySymbol = Symbol ( ‘mySymbol’ ) ;

Every time you call the factory function, a new and unique symbol is created.

 

 

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *