Everything a computer’s memory hold is Data and representing Data in JavaScript is called Value. Values need to be distinguished based on their role. So, JS divides its value to 6 different type.
- Number
- String
- Boolean
- Undefined
- Function
- Object
Number :
It helps you to represent the numerical data in JS. There are several arithmetic operations like addition , subtraction , multiplication, division, modulus etc. which acts on the numeric values in order to perform mathematical calculations. Calculations in whole number will give us the precise value in JS but there might be some approximation taken when dealing with non-whole numbers calculations in JS. If you really want to represent a very big number (like astronomical numbers) in JS, you can use the ‘ e’ syntax (e stands for exponential ).
e.g. var number = 10*e5; or var number = 10*e-10;
NaN, Infinity, -Infinity are also of Number type
Strings:
It helps you to represent any character in JS but make sure to keep them inside quotes (the starting quote needs to match with the ending quote). Strings can’t be multiplied, divided, subtracted but we can add them. Concatenation is the way in which we can add two strings, for that we use ‘+’ operator.
e.g. var data = 'two' + 'strings';
data will give us the result twostrings.
Boolean:
It holds a value which distinguishes between two possibilities true or false.
Logical operator is used for Boolean values.
&& (Logical And) : It is a binary operator. If both the values applied to it are true then only the result is true
||(Logical Or) : It is a binary operator. If any of the values applied to it is false then the result is false else it will be true
! (Logical not) : It is a unary operator. It used for flipping the value. When we give it true, we get the result as false, the same works for false also.
Undefined :
It denotes the absence of a meaningful value. There are two values one is null and another is undefined which don’ t carry any meaningful information. There are some differences between null and undefined , one of them is their type — typeof(null) is object but typeof(undefined) is undefined
Function :
A piece of program wrapped in brackets in order to produce a value is called a function. Function may return a value or it may produce any visible clue or internal state change. You can also write a function which does the both.
Functions are the only thing that produces a scope. Control flow structures don’t produce any scope in Javascript.
Objects :
Objects are the value that allow us to group different types of value (object also).
Objects consist property which will contain any value (functions also). By using these properties, we can manipulate with the Object.