Skip to content
  • Quizes
  • QStack
  • Blog
  • pinterest
  • instagram
  • twitter
  • linkedin
  • facebook
W3 Coding Schools
  • Home
  • HTML
    • HTML Introduction
    • HTML Editors
    • Fundamentals of HTML
    • Elements of HTML
    • HTML Attributes
    • HTML Headings
    • HTML Paragraphs
    • HTML Style Attribute
    • HTML Text Formatting
    • HTML Phrase Tags
    • HTML Comments
    • HTML with CSS
    • HTML Links
    • HTML Images
    • HTML Tables
    • HTML Lists
    • HTML Blocks
    • HTML Class Attribute
    • HTML Id Attribute
    • HTML Iframes
    • HTML JavaScript
    • HTML File Paths
    • HTML Head
    • Computer Code Elements
    • HTML Entities
    • HTML Charset
    • HTML URL Encode
    • HTML and XHTML
    • HTML Layouts
    • HTML Forms
    • HTML Form Elements
    • HTML Form Input Types
    • HTML Input Attributes
    • HTML5 Introduction
    • HTML5 New Elements
    • Semantic Elements
    • HTML5 Migration
    • Style Guide
    • HTML Canvas
  • CSS
    • CSS Introduction
    • CSS Syntax and CSS Comments
    • CSS Selectors
    • How to add CSS to a Webpage
    • CSS Color Basics
    • CSS Background Properties
    • CSS Border Properties
    • CSS Margin and Padding Properties
    • CSS Height and Width properties
    • CSS Box Model
    • CSS Outline Properties
    • CSS Fonts
    • CSS Text
    • How To Add Icons
    • CSS Links
    • CSS List-Style
    • CSS Tables
    • CSS Display Property
    • CSS Position Property
    • CSS Overflow Property
    • CSS max-width Property
    • CSS Float and Clear Properties
    • CSS Alignment
    • CSS inline-block
    • CSS Combinators
    • CSS Pseudo Classes
    • CSS Pseudo Elements
    • CSS Opacity
    • CSS Navigation Bar
    • CSS Dropdowns
    • CSS Image Gallery
    • CSS Image Sprites
    • CSS Attribute Selector
    • CSS Styling Forms
    • CSS Counters
    • CSS Units
    • CSS Specificity
    • CSS Website Layout
    • CSS Rounded Corners
    • CSS Border Image Property
    • CSS Multiple Backgrounds
    • CSS Gradient
    • CSS Shadow Effects
    • CSS Text Effects
    • CSS Web Fonts
    • CSS 2D Transforms
  • Bootstrap 4
    • Bootstrap 4 – Introduction
    • Bootstrap versions
    • Bootstrap 4 Layout
    • Bootstrap 3 Vs Bootstrap 4
    • Bootstrap 4 Grid System
    • Bootstrap 4 Typography
    • Bootstrap 4 Colors
    • Bootstrap 4 Images
    • Bootstrap 4 Tables
    • Bootstrap 4 Jumbotron
    • Bootstrap 4 Figures
    • Bootstrap 4 Alerts
    • Bootstrap 4 Buttons
    • Bootstrap 4 Button Group
    • Bootstrap 4 Badges
    • Bootstrap 4 Spinners
    • Bootstrap 4 Progress Bars
    • Bootstrap 4 Pagination
    • Bootstrap 4 Breadcrumbs
    • Bootstrap 4 List Groups
    • Bootstrap 4 Cards
  • jQuery
    • jQuery Introduction
    • jQuery Download
    • jQuery Selectors
    • jQuery Event Methods
    • jQuery Hide/Show Effects
    • jQuery Fading Effects
    • jQuery Sliding Effects
    • jQuery Animation
    • jQuery Stop and Callback
    • jQuery Get and Set Methods
    • jQuery Chaining
    • jQuery Add
    • jQuery Remove
    • jQuery CSS Classes
    • jQuery Style Properties
    • jQuery Dimensions
    • jQuery Traversing
    • jQuery Ancestors
    • jQuery Descendants
    • jQuery Siblings
  • Javascript
    • JS Introduction
    • JS Where to Put
    • JavaScript Syntax
    • JavaScript Comments
    • JavaScript Variables
    • JavaScript Data Types
    • JavaScript Operators
    • JavaScript Events
    • JavaScript Strings
    • JavaScript Numbers
  • php
    • PHP Introduction
    • Install PHP
    • PHP Syntax and Comments
    • PHP Variables
    • PHP Constants
    • PHP Echo and Print
    • PHP Data Types
    • PHP Strings
    • PHP Operators
    • PHP $ and $$ Variables
  • WordPress
    • WordPress Introduction
    • WordPress History
    • WordPress.com vs WordPress.org
    • How to Install WordPress
    • WordPress Dashboard
    • How to Create a WordPress Website
    • WordPress Posts
    • WordPress Pages
    • WordPress Posts vs Pages
    • WordPress Categories
  • SEO
    • SEO Introduction
    • SEO Tactics and Methods
    • SEO Relevant Filenames
    • SEO Domain Name
    • Website Design and SEO
    • SEO Keywords
    • Meta Tags Optimization
    • Title Tag Optimization
    • Anchor Text Optimization
    • Content Optimization
  • Android
    • Android Introduction
    • Android History and Versions
    • Android Architecture
    • Android Environment Setup
    • Android Application Components
    • Hello World Application
    • Android Activities
  • iOS
    • iOS Introduction
    • iOS Environment Setup
    • iOS Architecture

You Are Here

  • Home
  • Learn Javascript
  • JavaScript Data Types

Topics

  • JavaScript Numbers
  • JavaScript Strings
  • JavaScript Events
  • JavaScript Operators
  • JavaScript Data Types
  • JavaScript Variables
  • JavaScript Comments
  • JavaScript Syntax
  • JS Where to Put
  • JS Introduction

Oct Champs & Prizes

  • 1. Pooja Ladda
  • 2. Manjali Kuldharan
  • 3. Pranali Surawar
  • 4. Anjali Kulkarni
  • 5. Vishal Deshmukh

Recent Posts

  • HTML Media
  • jQuery Siblings
  • Bootstrap 4 Cards
  • jQuery Descendants
  • jQuery Ancestors

JavaScript Data Types

JavaScript data types are used to specify what kind of data can be stored and manipulated in a program. JavaScript data types tell the compiler whether the data value is numeric, alphabetic, date, etc. so that it can perform the appropriate operation.
Primitive data types can hold only one value at a time and non-primitive data types can hold collections of values and more complex entities.
JavaScript data types are divided into two main categories:

Primitive Data Types:

  • String
  • Number
  • Boolean
  • Undefined
  • Null

Non-primitive Data Types:

  • Object
  • Date
  • Array

Primitive Data Types:

The String Data Type:

The data type string is used to represent textual data i.e. sequences of characters and the strings are created using single or double-quotes.

Example:

var a = 'Hello'; // using single quotes
var b = "Learn JavaScript"; // using double quotes
Try it
You can include quotes inside the string as long as they don’t match the enclosing quotes.

Example:

var a = "Let's learn JavaScript";
var b = 'He said "Hello" and left.';
var c ="He said 'Hello' and left.";
Try it
You will learn more about the strings in our JavaScript strings topic.

The Number Data Type:

The data type number is used to represent positive or negative numbers with or without decimal place, or numbers are written using exponential notation e.g. 1.5e-4.

Example:

var a = 24.00;
var b = 24;
var c = 2.47;
document.getElementById("trial").innerHTML = a + "<br>" + b + "<br>" + c;
Try it
The extra-large or extra small numbers in JavaScript can be written with the exponential notation.

Example:

var a = 456e5;
var b = 456e-5;
document.getElementById("trial").innerHTML = a + "<br>" + b;
Try it
You will learn more about the strings in our JavaScript numbers topic.

The Boolean Data Type:

The Boolean data type holds only two values i.e true or false. It is used to store values like yes (true) or no (false), on (true) or off (false), etc.

Example:

var a = 6;
var b = 7;
var c = 6;
document.getElementById("trial").innerHTML = (a == b) + "<br>" + (a == c);
Try it

The Undefined Data Type:

The undefined data type can only have one value i.e undefined. If a variable is declared but the value is not assigned to it then it has the value undefined.

Example:

var a; // Value is undefined, type is undefined
document.getElementById("trial").innerHTML =
a + "<br>" + typeof a;
Try it

The Null Data Type:

In JavaScript, a null value means that there is no value, it is not equivalent to an empty string (“”) or 0, it is simply nothing. It has only one value i.e the null value.
A variable can be explicitly emptied of its current contents by assigning it to the null value. In JavaScript, the data type of null is an object.
Emptying an object by setting it to null:

Example:

var person = {firstName:"David", lastName:"Miller", age:30, eyeColor:"brown"};
person = null; //Value is null, but type is still an object
document.getElementById("trial").innerHTML = typeof person;
Try it
Emptying an object by setting it to undefined:

Example:

var person = {firstName:"David", lastName:"Miller", age:30, eyeColor:"brown"};
person = undefined; // Both value and type is undefined
document.getElementById("trial").innerHTML = person;
Try it

Non-primitive Data Type:

The Object Data Type:

The object is a non-primitive data type that allows you to store collections of data. An object contains properties and defined as a key-value pair. A property key (name) is always a string, but the value can be any data types, like strings, numbers, booleans, or complex data types like arrays, function and other objects.

Example:

var person = {
firstName : "David",
lastName : "Miller",
technology: "JavaScript"
};
document.getElementById("trial").innerHTML =
person.firstName + " is learing " + person.technology + ".";
Try it

The Array Data Type:

An array is object type is used for storing multiple values in a single variable. Each value in an array has a fixed position, known as its index, and it may contain data of any data type-numbers, strings, booleans, functions, objects, and even other arrays. The array index starts from 0 so the first array element is arr[0], not arr[1].
The easiest way to create an array is by specifying the array elements as a comma-separated list enclosed by square brackets.

Example:

var technologies = ["HTML","CSS","JavaScript", "jQuery"];
document.getElementById("trial").innerHTML = technologies[2];
Try it

The typeof Operator:

The typeof operator is used to find out what type of data a variable contains. It is used with or without parentheses (typeof(x) or typeof x).

Example:

document.getElementById("trial").innerHTML =
typeof "" + "<br>" + // Returns "string"
typeof "David" + "<br>" + // Returns "string"
typeof "David Miller" + "<br>" + // Returns "string"
typeof 0 + "<br>" + // Returns "number"
typeof 24 + "<br>" + // Returns "number"
typeof 2.47 + "<br>" + // Returns "number"
typeof (2) + "<br>" + // Returns "number"
typeof (2 + 3); // Returns "number
Try it

Post navigation

JavaScript Variables
JavaScript Operators

Ask a Question Cancel reply

Your email address will not be published. Required fields are marked *

W3 CODING SCHOOLS © Copyright 2019-20
Privacy policy   Terms of use

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok