javascript Tutorial

JavaScript Data Types

Learn more about one of the world’s most popular programming languages.

Every programming language is designed around storing information for your application or website. When storing this information, there is always a need to specify what kind of information is being stored. It could be numerical information or textual data. Sometimes it could be a logical state and sometimes it is a collection or list of information. Hence, every programming language ships with built-in data types also known as primitive data types.


Data Types in JavaScript

JavaScript as a language provides the following eight basic data types:

  • Number
  • String
  • Boolean
  • Null
  • Undefined
  • BigInt
  • Symbol
  • Object

Here is a brief description of each of the eight basic JavaScript data types:

JavaScript Number

Number in JavaScript represents integer numbers or a floating-point number. A number type could also be +Infinity-Infinity, and NaN (not a number).

JavaScript Strings

The string type is used to represent textual data.

JavaScript Boolean

The boolean data type represents logical entities. Boolean values represent truth values: true or false.

JavaScript Null

Null in JavaScript represents an unknown or empty value.

JavaScript Undefined

The undefined data type represents a variable that has not been assigned a value.

JavaScript BigInt

BigInt can represent integers with arbitrary precision, allowing you to store and operate on larger numbers beyond the integer limit.

JavaScript Symbol

If a value has the symbol data type, it is an immutable and unique primitive value.

JavaScript Object

The non-primitive, complex data type object allows you to store multiple data collections. Arrays are a type of object whose keys are integers. Arrays are a key building block for complex data structures.


Dynamic and Weakly Typed Language

It is important to note that JavaScript is a dynamic and weakly typed language, so the same variable can be used to hold a variety of different data types. JavaScript variables assigned a value of a certain type can be re-assigned a value of a different type because they are dynamically used by the JavaScript engine.

Code Example
let response = ‘Success’;
console.log(response); // prints ‘Success’

response = true;
console.log(response); // prints true

Typeof Operator

Considering JavaScript is a weakly-typed, dynamic language, it also provides Developers with typeof operator that helps to understand the data type being stored in a certain variable at any given point in time.

Code Example
const grade = 100;
console.log(typeof grade); // prints number

const greeting = ‘Merry Christmas’;
console.log(typeof greeting); // prints string

const hasGraduated = true;
console.log(typeof hasGraduated); // prints boolean

JavaScript String Length

Sometimes while using strings in JavaScript, there is a need to know the length of the string or textual information stored in a JavaScript variable. JavaScript provides length property for the same. length property is commonly used when there is a need to find the length of a string or many other data types in JavaScript.

Code Example
const greeting = ‘Merry Christmas’;
console.log(greeting.length); // prints 15;

Learn JavaScript Today

Get hands-on experience writing code with interactive tutorials in our free online learning platform.

  • Free and fun
  • Designed for beginners
  • No downloads or setup required