This content originally appeared on DEV Community and was authored by Nirbhay Parmar
If you are a beginner in web development then you must learn the JavaScript. It powers the interactions on each and every webpages. Basically it enables the websites to interact with the user in many ways like music player, alert, pop-ups or a video player or animations.
But to create such interactions on the websites developers need to write the code that take user inputs or call an api to get any data, but to do all this things we need some type of storage container that will store different types of data like numbers, strings, objects or boolean. So each programming languages defines some data types to sort the things out.
The JavaScript is a "dynamically typed" language, we not have to specify the data types at variable declaration unlike C/C++ or Java. Variables can store any data type in it. There are total 8 data types in JavaScript. These are as follows-
- Number
- String
- BigInt
- Boolean
- Null
- Undefined
- Object
- Symbol
Number
Numbers as the name suggest, it used to store numbers. Numbers can be integers, fractions, or Infinity/-Infinity and NaN(Not a Number).
Example-
let int = 123; // integer
let fraction = 1.2 // fraction
let infinity = Infinity // Infinity
String
String is the type of data in which, there is a bunch of alphanumeric characters and other symbols are together. In other words, it is a group of characters. Strings are to be surrounded by quotes, single or double.
Example-
let str = "abc123,./";
// string can have alphanumeric and other symbols
alert( `The back-tics can used to use variables in in between the string like str is- ${str}!` );
// The back-tics can used to use variables in in between the string like str is- abc123,./
BigInt
BigInt is made to accommodate really large numbers which are more than 2^53 -1 or less -(2^53 -1) due to its technical limitations. They are represented by appending 'n' after the number.
Example-
let bigint = 123456789123456789123456789n;
Boolean
Boolean is used to represent true or false values. Sometimes we only two values for our function or we have to check some condition that is true or false.
Boolean values can also come as a result of comparision.
Example-
let isTrueOrFalse = true;
let firstIsGreaterOrNot = 7 > 9;
console.log(firstIsGreaterOrNot); // false
Null
People often confused between null value and undefined value(non existing value). Null values represents "nothing", "empty" or "unknown".
Example-
let value = null;
console.log(value); // null
Undefined
They are different then Null data types. They represents that the variable is not assigned any value.
Example-
let name;
console.log(name); // undefined
Object
Objects are non primitive data type. We can defined key-value pairs. We can store any type values in one such object. We can store collections of data of different data types.
Example-
let obj =
{
name: Nirbhay,
age: 19,
isIndian: true
}
Symbol
Symbol are used to create unique identifiers for objects. They can used to generate unique identifiers.
No example for this because i have to read more on it.
This post is based on what I learned about data types in JavaScript from javascript.info. It is basically a summary of that article. Visit it to get some deeper understanding.
cover photo by Pankaj Patel on Unsplash
This content originally appeared on DEV Community and was authored by Nirbhay Parmar
Nirbhay Parmar | Sciencx (2021-11-09T19:40:09+00:00) All Data Types in JavaScript. Retrieved from https://www.scien.cx/2021/11/09/all-data-types-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.