JavaScript values are defined with literals. Literals are fixed values that you provide inside your script.In the following statements, the string, number, Boolean value or list of key:value pairs, etc.

There are 6 types of literals that can be used in JavaScript

array literals      Boolean literals      floating-point literal     integers      object literals      string literals

Below are some examples of literals. The literals are highlighted.

var dogNames = ["Fido", "Tippy", "Spot", "Goldie"];  // info in brackets is an array literal
var testAnswer = true;  //true is a Boolean literal
var intRate = 0.04156;  //0.04156 is a floating-point literal
var numParticipants = 25;  // 25 is an integer
var carSpecs = {make : "Toyota", model : "Camry LE", year : "2006", used : true};  // info in brackets is an object literal
var coffeeType = "Kona";  // "Kona" is a string literal

Three dot cartouche

Array Literals

An array literal is a list of elements, separated by commas, enclosed inside of square brackets [  ]. You can have 0 elements or multiple elements inside of the brackets. The length of the array is the number of elements in the array. Certain functions in JavaScript can add to this array or take elements out of the array. You can have empty space between commas, this may be so that you can fill in the space with a value later in the script. Arrays can have a mixture of the type of values.

var catNames = ['Felix", "Sassy", "Claws"]  // the info between the brackets is an array literal
var userInfo = ["Wanda", 2014, false, , "Admin Level"]; // note the mixture of value types and the empty space between commas

Do not get array literals mixed up with object literals. Array literals are in [ ] square brackets and do not have sets of key : value pairs.

Three dot cartouche

Boolean Literals

A Boolean literal will be either true or false.

var testResult = true;
var entryTest = false;

Three dot cartouche

Floating-point Literals

A floating point literal will be a number with a decimal point, a fraction or an exponent. A floating point literal can have a + or - sign preceding. If there is no sign preceding the number, it is assumed to be positive.

var pace = 12.34;
var intRate = .1305;
var redRate = -25;

Three dot cartouche


An integer is a whole number with no decimal point. Integers can have a + or - sign preceding. If there is no sign preceding the number, it is assumed to be positive. Integers can be in decimal (base 10), hexadecimal (base 16) or octal (base 8).

A whole number will be assumed to be decimal number. For octal numbers, precede the whole number with 0. For hexadecimal numbers, precede the whole number with 0x

var numParticipants = 38; // this is a decimal integer
var g = 034; // 034 is a octal integer
var y = 0x1145 // ox1145 is a hexadecimal integer

Three dot cartouche

Object Literals

An object literal is a list of 0 or more key : value pairs, also referred to as name : value pairs, enclosed in curly braces. 

var house = {sf = 1400, stories : 3, basement : true, color : "tan", year : "2007"};

Three dot cartouche

String Literals

A string literal is 0 or more characters enclosed in single ' ' or double quotation " " marks. 

var fName = "Sally";
var motto = "Always be sure";
var address = '234 Elm Avenue';