Data Types in JavaScript

How many data types are there in JS, and what are they? And what are the scopes?

Last updated:7/19/2021 5:23:37 AM

2 Answers

Ethan Karla
Ethan Karla

Data types basically specify what kind of data can be stored and manipulated within a program.

There are six basic data types in JavaScript which can be divided into three main categories: primitive (or primary), composite (or reference), and special data types.

String, Number, and Boolean are primitive data types. Object, Array, and Function (which are all types of objects) are composite data types. Whereas Undefined and Null are special data types.

Primitive data types can hold only one value at a time, whereas composite data types can hold collections of values and more complex entities

Ethan Karla
Ethan Karla

JavaScript operators are symbols that are used to perform operations on operands. For example:

var sum=10+20;

Here, + is the arithmetic operator and = is the assignment operator.

There are following types of operators in JavaScript.

  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Assignment Operators
  • Conditional Operators

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations between numeric operands.

Comparison Operators

JavaScript language includes operators that compare two operands and return Boolean value true or false.

Logical Operators

Logical operators are used to combine two or more conditions. JavaScript includes following logical operators.

Assignment Operators

JavaScript includes assignment operators to assign values to variables with less key strokes.

Ternary Operator

JavaScript includes special operator called ternary operator :? that assigns a value to a variable based on some condition. This is like short form of if-else condition.