What are the Data types in JavaScript? Description and Examples

Do you want to know what are the different data types in JavaScript? Read on!

In this article, we will show you the different data types that you should know while working with JavaScript.

By that, you’ll learn how to use them effectively in your programs. This article provides a detailed description and examples of each data type. 

If you want to improve your understanding of JavaScript data types, let’s get started!

What are the Data types in JavaScript?

Data types in JavaScript refer to the different types of values that can be stored in a variable.

There are eight (8) data types in JavaScript, that specify what kind of data can be stored and manipulated within a program.

These data types are String, Number, BigInt, Boolean, Undefined, Null, Symbol, and Object.

The first six (6) of these data types (String, Number, BigInt, Boolean, Undefined, and Null) are considered primitive data types, meaning they are the lowest level of implementation of a programming language and are not objects.

The last two (2) (Symbol and Object) are composite data types, meaning they can be composed of other data types.

Here is a brief description and examples of the eight data types in JavaScript:

String

A string is a sequence of characters used to represent text. It is created by enclosing characters in single or double quotes.

Single quotes: ‘Itsourcecode’

Double quotes: “Itsourcecode”

Backticks: `Itsourcecode`

For example:

let samplestring = "Hi, Welcome to Itsourcecode!";

You also have the ability to include quotation marks within a string, provided they do not match the quotation marks that enclose the string.

let samplestring = 'Welcome to "Itsourcecode"';

Number

A number is a numerical value, which can be an integer or a floating-point number.

The majority of programming languages encompass a variety of numeric data types:

✔ Whole numbers (integers):

  1. byte (8-bit)
  2. short (16-bit)
  3. int (32-bit)
  4. int (32-bit)

✔ Real numbers (floating-point):

  1. float (32-bit)
  2. double (64-bit)

In JavaScript, numbers are only of a single type: double (64-bit floating point).

For example:

let samplenumber = 3.14; (With decimal)

let samplenumber = 3; (Without decimal)

The number data type can also represent +Infinity, -Infinity, and NaN (not a number).

Example 1:

const samplenumbe1 = 10/0;
console.log(samplenumbe1);

Output:

 Infinity

Example 2:


const samplenumbe2 = -10/0;
console.log(samplenumbe2);

Output:

-Infinity

Example 3:

const samplenumbe3 = "xyz"/1; 
console.log(samplenumbe3); 

Output:

NaN

📌 Note: Strings can’t be divided to any numbers that’s the reason why it will return Nan.

BigInt

A BigInt is an integer with arbitrary precision, meaning it can represent numbers larger than the maximum safe integer in JavaScript (2^53 – 1).

It is created by appending n to the end of an integer literal.

For example:

 let sampleBigInt = 1234567890123456789012345678901234567890n;

📌Please be aware that BigInt was introduced in a more recent JavaScript version and is not compatible with several browsers, including Safari.

Boolean

A boolean represents a logical value, either true or false.

For example:

let a = 10;
let b = 10;
let c = 20;
console.log(a == b);    // true   
console.log(b == c);    // false 

Output:

true
false

Undefined

A variable that has been declared but has not been assigned a value is undefined.

For example:

let sampleVariable;
console.log(sampleVariable);

Output:

undefined

Null

The value represents the intentional absence of any object value. It is often used to indicate that a variable should have no value.

In a simple understanding, null is a special value that means something is empty or unknown in JavaScript.

For example:

let sampleVariable = null;

Symbol

A symbol is a unique and immutable primitive value that can be used as the key of an object property. It is created using the Symbol() function.

For example:

let value = Symbol('Itsourcecode');

Object

An object is a collection of properties, where each property has a name and a value.

It can be created using object literal syntax or the Object() constructor.

let sampleObject = {key1: "value1", key2: "value2"};

Here’s a complete example:

const employee = {firstName:"Anna", lastName:"Smith", age:18, address:"USA"};
console.log(employee)

Output:

{ firstName: 'Anna', lastName: 'Smith', age: 18, address: 'USA' }

How many data types are there in JavaScript?

As we mentioned earlier, there are eight data types in JavaScript, that’s include the following:

  1. String
  2. Number
  3. BigInt
  4. Boolean
  5. Undefined
  6. Null
  7. Symbol
  8. and Object

How to change data type in JavaScript?

In order to change the data type in JavaScript, it can be done either by using a JavaScript function or automatically by JavaScript itself.

For instance, to convert a string to a number, you can use the global method Number(), which converts a variable (or a value) into a number.

Here’s an example:

let samplestring = "3.14";
let myNumber = Number(samplestring);
console.log(myNumber); 

Output:

3.14

Similarly, to convert a number to a string, you can use the global method String(), which can convert numbers to strings. It can be used on any type of numbers, literals, variables, or expressions.

Here’s an example:

let sampleNumber = 18;
let sampleString = String(sampleNumber);
console.log(sampleString);

Output:

"18"

How to check data type in JavaScript?

You can use the typeof operator to check the data type of a variable or value.

The typeof operator is a keyword in JavaScript that returns a string indicating the type of the operand’s value.

It can be used to determine the data type of a variable or expression.

The typeof operator returns a string that indicates the type of the operand that hasn’t been evaluated yet.

Here are some examples of using the typeof operator:

typeof "Itsourcecode" // Returns "string"

typeof 3.14 // Returns "number"

typeof NaN // Returns "number"

typeof false // Returns "boolean"

typeof [10, 20, 30, 40, 50] // Returns "object"

typeof {name:'Anna', age:18} // Returns "object"

typeof new Date() // Returns "object"

typeof function () {} // Returns "function"

typeof myCar // Returns "undefined" *

typeof null // Returns "object"

📌Please note that the typeof operator returns “object” for arrays, dates, and null.

Conclusion

Data types in JavaScript refer to the different types of values that can be stored in a variable and it has eight data types: String, Number, BigInt, Boolean, Undefined, Null, Symbol, and Object.

Each data type has its own unique properties and uses, and understanding how to use them effectively is essential for writing efficient and effective JavaScript programs.

This article has provided detailed descriptions and examples of each data type, along with explanations of how to change and check data types in JavaScript.

We are hoping that this article provides you with enough information that help you understand the data types in JavaScript.

If you want to dive into more JavaScript topics, check out the following articles:

Thank you for reading Itsourcecoders 😊.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.
Caren Bautista

Technical Writer at PIES IT Solution

Responsible for crafting clear, well-structured, and beginner-friendly content across the platform. Handles the writing, proofreading, and editorial review of tutorials, guides, and documentation to ensure every article is accurate, readable, and easy to follow.

Expertise: Technical Writing · Content Creation · Documentation · Editorial Writing · JavaScript · TypeScript · Python · Python Errors · HTTP Errors · MS Excel  · View all posts by Caren Bautista →

Leave a Comment