Data Types in JavaScript

Data types describe the characteristics of data stored in a variable. Data types can be divided into two:

Primitive Data types
Non-primitive Data types

1. Primitive Data Types
Primitive data types are immutable or non-modifiable data types. Once a …


This content originally appeared on DEV Community and was authored by Khyati Baria

Data types describe the characteristics of data stored in a variable. Data types can be divided into two:

  • Primitive Data types
  • Non-primitive Data types

1. Primitive Data Types
Primitive data types are immutable or non-modifiable data types. Once a primitive data type is created we cannot modify it. Primitive data types in JavaScript include:-

Number
Number datatype can stores both integers and decimal values. Using Number data type we can do all the arithmetic operations.
let age = 21;
var quantity= 12;
const gravity = 9.81 // we use const for non-changing values

Strings
Strings data type are used to store textual data. To declare a string, we need a variable name, assignment operator, and a value under a single quote, double quote, or backtick quote.
let userName = "Khyati";
let city = 'Mumbai';
let language = 'JavaScript';
let space = ' '; // an empty space string

Booleans
The Boolean data type can store only two values i.e. true and false.This type is commonly used to store yes or no types values.
var yes = true;
var no= false;

Null
null data type is special type of placeholder in JavaScript. Null value represents the intentional absence of any object value.
var vaule = null;

Undefined
The undefined data type is special type of placeholder in JavaScript, undefined means “value is not assigned”. If a variable is declared, but not assigned, then its value is undefined.
var userName;
console.log(userName); // shows "undefined"

2. Non-primitive Data Types
Non-primitive data types are modifiable or mutable. We can modify the value of non-primitive data types even after it gets created. Non-primitive data types in JavaScript includes:-

Arrays
Arrays data type are used to store multiple values at a time in single variable. An array is a list of values store within a variable, and can access these values by referring to their index number.
let numbers = [1, 2, 3];
let fruits=['apple', 'banana', 'mango'];

Objects
Objects are the complex data type in JavaScript. Object tries to map real like things in programing. Object stores the data in form of key value pair. Where key is string and value can be anything.
let car={
name: 'Honda City',
model: 'VMT' ,
color: 'Black',
}

So this is it for this article. If you find it informative please leave a like and consider following me. Thanks for reading.


This content originally appeared on DEV Community and was authored by Khyati Baria


Print Share Comment Cite Upload Translate Updates
APA

Khyati Baria | Sciencx (2021-12-09T09:50:19+00:00) Data Types in JavaScript. Retrieved from https://www.scien.cx/2021/12/09/data-types-in-javascript/

MLA
" » Data Types in JavaScript." Khyati Baria | Sciencx - Thursday December 9, 2021, https://www.scien.cx/2021/12/09/data-types-in-javascript/
HARVARD
Khyati Baria | Sciencx Thursday December 9, 2021 » Data Types in JavaScript., viewed ,<https://www.scien.cx/2021/12/09/data-types-in-javascript/>
VANCOUVER
Khyati Baria | Sciencx - » Data Types in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/09/data-types-in-javascript/
CHICAGO
" » Data Types in JavaScript." Khyati Baria | Sciencx - Accessed . https://www.scien.cx/2021/12/09/data-types-in-javascript/
IEEE
" » Data Types in JavaScript." Khyati Baria | Sciencx [Online]. Available: https://www.scien.cx/2021/12/09/data-types-in-javascript/. [Accessed: ]
rf:citation
» Data Types in JavaScript | Khyati Baria | Sciencx | https://www.scien.cx/2021/12/09/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.

You must be logged in to translate posts. Please log in or register.