- Primitive data types
- Special data types
- Composite data types
Number type, string type, and boolean type are considered primitive data types. Undefined types and null types are considered Special datatypes. Object types are considered composite types. Let’s discuss primitive datatypes.
What is a primitive datatype?
It is also called value types, we can create two different types of variables one value type and another one is a reference type. Value type variables hold the value they hold a value or a given value directly whereas reference type variables hold a reference to a pointer or address of another memory location. They are divide into three:
It Indicates both integer and real numbers.
It means whole numbers, numbers that don’t contain a floating point or a decimal point. All below are examples of integers, which means negative infinity to positive infinity any number which has no decimal point is considere an integer.
Ex: 12, 2000, -400, etc
Numbers containing floating points are real numbers or float numbers. In the given below all numbers are examples of real numbers. we can use both variable and constant for initializing integer
Ex: 3.25, 9,0, -15,3 etc
var playerscore=10 ; const PI= 3.142; document.write("Player Score = ", playerscore,"<br/>","PI = ", PI)) ;
Player Score = 10
PI = 3.142
It indicates the sequence of characters enclosed in double quotations or single quotations. i.e. Textual data. So, the string is one or more characters enclosed in quotations.
If a string begins with single quote then it has to end with single quote and If a string begins with double quote then it has to end with double quote, you can don’t mismatch.
var player="Johny"; document.write("Player Name = ", player);
Player Name = Johny
var gameover = false; document.write("Type of Is Game Over = ",typeof gameover);
Type of Is Game Over = boolean
In the above code, we assign a “false” value to the variable gameover. We check the data type using “typeof” keyword it returns a boolean.