JavaScript Tutorials


» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls


» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement


» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop


» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions


» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays


» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword


» Introduction to AJAX


» Introduction to JSON


» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)


» Math Object

» Math Methods


» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events


» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript


» JavaScript Calculator

.. » JavaScript » Introduction » JavaScript Data Type
Share Tweet WhatsApp

JavaScript Data Type

A data type in JavaScript is simply the kind of data or characteristics of a value or a value stored on a variable. If you are asked, what data type is 5? I believe you will reply "5 is a number" and yes, that is a data type in JavaScript. Every variable or value you use in JavaScript has a data type. If no value exists, then, the data type is undefined. if no value exists or exists yet but we want to assign a value representing an absence of value, then, the data type of null can be assigned. If the value is a positive or negative number, decimal or non decimal number e.g 5 or - 9.1, then, the data type is a number If the value is contained in single or double quotes e.g "5" or 'Hello World', then, the data type is a string If the value is true or false e.g var bool = true, then, it is a boolean. if the value is enclosed in brackets([]) e.g [1, "Hello World"], then, it is an array. if the value is enclosed in curly braces in name:value pairs e.g {name:"omamode"}, then, it is an object if it is a JavaScript function e.g function myFunc(){}, then, it is a function. It is therefore important you know what data type each of your values and variables holds so as to know what operations are possible with such data types. For example, you can't subtract a "string" from a "number".
var diff = 5 - "Two"; //Doesn't make sense
var num = 5;
var str = "Hello World";
var bool = true;
var arr = [1, 2, 3];
var obj = {one:1, two:2, three:3};
var func = function(){

alert(typeof(num)); //number
alert(typeof(str)); //string
alert(typeof(bool)); //boolean
alert(typeof(arr)); //object. We will discuss why later
alert(typeof(obj)); //object
alert(typeof(func)); //function


Primitive Data Types Primitive data types are those JavaScript data types that ordinarily do not possess an object for creating or manipulating them. They are JavaScript original data types that can be created the literal way. There are five(5) primitive data types in JavaScript namely: 1. Numbers 2. Strings 3. Booleans 4. Undefined 5. Null But then, all JavaScript data types now have objects for their manipulation. JavaScript Is A Loosely Typed Language JavaScript is a loosely typed programming language. This is because you don't need to specify what data type the value of a variable is and a variable can contain values of different data types at different points of the program. Assume this is a JAVA program
int num = 22; //only numbers without decimal points can be stored on this variable
float myF = 4.8d; //numbers with decimal points are stored here
num = 5.6d; //Error
But JavaScript,
var myVar = 12; //stores a number
myVar = "Hello World"; //storing a string
myVar = [1, 3, 1]; //storing array
You will learn about the individual data types in subsequent pages. SUMMARY
  1. A data type is the type of data a value is or a variable holds.
  2. A variable without a value is undefined. If we also try to use a variable that doesn't exists, it is also undefined.
  3. null is a data type we assign to variables just the way we assign numbers or strings. We assign null to variables to depict the absence of value for such variables.
  4. A positive or negative number has a datatype of number.
  5. Anything contained in single (' ') or double (" ") quotes is a string
  6. Any variable whose value is either true or false is a boolean.
  7. Anything contained in brackets ([ ]) is an array. But arrays are objects.
  8. Anything contained in curly braces in name:value pairs is an object.
  9. A JavaScript function has a data type of function.
  10. Understanding variables' and values' data type helps in knowing what operations are possible with such values at every given point and how to operate with them.
  11. JavaScript is a loosely typed programming language.
  12. This is because you don't need to specify the data type of a value. This allows us to assign values of different data types to a variable at various instances of assignment.
Take a short quiz on JavaScript Data Type.
Ask a question or tell us if JavaScript Data Type is easy or not.

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.

StackBeginner 2021 © Joseph Omamode