Data Types in JavaScript
In this blog we will see different data types in JavaScript. So, first thing first, what is a data type? Data type refers to type of value. Let's see them with examples.
var, const is a keyword to declare variable
=(equal) assigns value on right side to left side
Number-
This data type stores any kind of numbers like without decimals and with decimals. Ex:
var num = 42; // number without decimal
var price = 25.25; // number with decimal
Strings-
This data type stores strings wrapped inside quotes( ' ' ," "). Ex:
var name = 'Riazo'; // string with single quote(')
var text = "Hello there!"; // string with double quotes(")
Boolean-
This data type can have only two values true or false. Ex:
var isActive = true; // boolean value true
var isPresent = false; // boolean value false
Additional read
Advanced data types
- Null- In simple terms, it means value does not exist. Ex:
var nullType = null; // null is a keyword
- Undefined- It usually occurs when value is not yet assigned. Ex:
var undefinedType = undefined; // undefined is a keyword
var undefinedType; // with undefined variable, output is similar as above
- BigInt- It stores any longest/ largest number which cannot be hold by Number type. Ex:
var bigIntType = 9848484844848484n; // 9848484844848484n
- Symbol- A Symbol is a unique and immutable type that may be used as key. Ex:
var symbolType = Symbol("symbol"); // undefined value on console
For more detailed and advanced data types you can check mdn docs.
Hope you learned and enjoyed reading :)