Introduction to JS Data Types
For a computer everything is 0s and 1s. A computer does not know the difference between “1234”, “QWERTY”. In a programming language all the general and common values we use are classified and organized. This distribution of values in a particular pattern can be called a Data Type. There are seven DataTypes. They are:
1. Number
The Number classification of data type includes all numbers. Javascript has only one type of Numbers.
It includes:
Some programming languages have different Data Types for Integer, Floating point numbers. But in Javascript,
Only one datatype for all kind of Numbers
All mathematical operations are possible in Javascript. Addition, Subtraction, Multiplication, Division, Comparison etc.
2. String
In all programming languages ‘String’ means simply text. Just simple as that. We can use this data type to write meaningful sentences in human understandable language.
Rules to use string
Both double quotes and single quotes can be used for Strings. Both quotes have no difference. Javascript accepts as string whatever we write inside double quotes or single quotes.
Backticks has an extended functionality, used to embed some other values to the string. Will explain later.
What if we write a number inside the quotes like “21” .?
Now the datatype of digit“21” changed to String datatype ie., Data type number changed to String
3. Boolean
Boolean Data Type holds two values
Boolean is exactly like a switch.
Either it is ON or OFF.
1 or 0
For the sake of explanation, we can say Yes or No, else Correct or Incorrect. While writing the program we should write “true” and “false”
4. Null
Null Datatype is a type of its own. Null Datatype is exactly what it means in English. ie.,
Nothing
Empty
Zero (or)
Doesn’t exist
We can use ‘null’ for the cases where, if something is empty or unknown for some reason. Null Data Type holds a single value null.
5. Undefined
undefined is also a type of its own like Null. undefined means
“the value is not assigned”.
Say we have something, but we have not explained or defined, what exactly the “something” is, then it is an undefined.
Are undefined and null the same .?
No, null means zero and undefined means the value for a variable is not assigned
6. Object
In Object we can store a collection of data using a key : value pair
eg:
Above example is just for understanding, *incorrect syntax*. Object Data Type can be combined of String, Number, Boolean, null Data Types.
7. Symbol
Symbol is a new Data Type introduced in ES6, Use case of symbol data type is to create an unique identifier for Objects. Symbols are immutable. Symbol is a function and it holds the value of data type Symbol. Unique identifier here means, if we are taking two same values, normally we can say it is equivalent or the same. But if we defining that value in a Symbol function as Symbol Data Type it is not the same or not equal. Thus we can use it for uniqueness.
typeof Operator
typeof operator can be used to find what kind of Data Type is variable.
Click the mouse on the right side of the blue > symbol.
Type “typeof” , the suggestions will appear.
There you can search for the type of Data.
Last updated
Was this helpful?