JavaScript Declarations and Assignments Data Types


JavaScript variables can hold many data types: numbers, strings, arrays, objects and more:

// Number
var length = 16;

// String
var message = "Hello, World!"; 

// Array
var carNames = ['Chevrolet', 'Nissan', 'BMW']; 

// Object
var person = {
    firstName: "John",
    lastName: "Doe"

JavaScript has dynamic types. This means that the same variable can be used as different types:

var a;              // a is undefined
var a = 5;          // a is a Number
var a = "John";     // a is a String