Primitive data types
Primitive data types only contain a single value. They can't contain a number of values. It includes further :
1. Number
Numbers is a primitive data type in JavaScript. Whether its a decimal number or not both are type of numbers. How do we calculate these values . For this we use ( typeof ) operator. This operator accepts a value and tells us the type of that value. In simple terms, any numeric value integer or decimal is considered to be number type in javascript. To operations on number we use :
( + ) for addition
( - ) for subtraction
( * ) for multiplication
( / ) for division
There are some special numbers like ( infinity ) and ( NaN - Not a Number - it is a type of value that can't be represented in numbers) .
2. String
String is a primitive data type in JavaScript. A string is textual content. It must be enclosed in single or double quotation marks. Since, string is character index, it can be accessed using for loop and for-of loop. The start and end mark of the string should be the same. We can perform operations on string using the join operators.
"Hello " + "World" = 'Hello World'
"Join" + "ed" = 'Joined'
3. Boolean
Boolean is a primitive data type in JavaScript. It is used to check the value is true or false, mostly used with comparison operators and logical operators.
A Boolean expression is any expression that has a Boolean value. For example, the comparisons
3 < 5
x < 5
x < y and Age < 16
are Boolean expressions. The comparison x < y will give the result true when the variable x contains a value that is 'less than' the value contained by the variable y. Boolean only results true or false . We can also apply ( not operator ) that flips/converts the value. This operator also known as flip operator. For example :
!True = False
!False = True
4. Undefined
Undefined is a premitive data type in javascript. It is also known as empty value. It is used to show the absence of any meaningful data. A variable has an undefined value when no value is assigned before using it. So you can say that undefined means lack of value or unknown value.
An undefined value in JavaScript is a common occurrence— it means a variable name has been reserved, but currently no value has been assigned to that reference. There is only one value for undefined and it is undefined itself. We only use this value where any operation does not produce any meaning value. undefined typically means a variable has been declared but not defined yet.
Let x = undefined
typeof (x) is 'undefined'
5. Null
Null is a premitive data type in javascript. It is also known as empty value. It is used to show the absence of any meaningful data. The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy for boolean operations. null is an assigned value. It means nothing.