bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/JavaScript/JavaScript Foundations
JavaScript•JavaScript Foundations

JavaScript Primitives

Concept visual

JavaScript Primitives

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

A

JavaScript variable can hold

8 types of data. 7 Primitive types or an Object type.

Examples

// Number let length = 16;
let weight = 7.5;
// BigInt let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)
// Strings let color = "Yellow";
let lastName = "Johnson";
// Boolean let x = true;
let y = false;
// Undefined let x;
let y;
// Null let x = null;
let y = null;
// Symbol const x = Symbol();
const y = Symbol();

JavaScript Strings

A string (or a text string) is a series of characters like "John Doe". Strings are written with quotes. You can use single or double quotes:

Example

// Using double quotes:

let carName1 = "Volvo XC60";

// Using single quotes:

let carName2 = 'Volvo XC60';

Try it Yourself » You can use quotes inside a string, as long as they don't match the quotes surrounding the string:

Example

// Single quote inside double quotes:

let answer1 = "It's alright";

// Single quotes inside double quotes:

let answer2 = "He is called 'Johnny'";

// Double quotes inside single quotes:

let answer3 = 'He is called "Johnny"';

Try it Yourself »

Learn More:

JavaScript String Methods

JavaScript String Search

JavaScript String Reference

JavaScript Numbers

All JavaScript numbers are stored as decimal numbers (floating point). Numbers can be written with, or without decimals:

Example

// With decimals:

let x1 = 34.00;

// Without decimals:

let x2 = 34;

Try it Yourself »

Exponential Notation

Extra large or extra small numbers can be written with scientific (exponential) notation:

Example

let y = 123e5;    // 12300000 let z = 123e-5;   // 0.00123

Try it Yourself »

Number Types

Most programming languages have many number types:

Whole numbers (integers):

byte

Formula

(8 - bit), short
(16 - bit), int
(32 - bit), long
(64 - bit)

Real numbers (floating-point):

float

Formula

(32 - bit), double
(64 - bit).
Javascript numbers are always double (64 - bit floating point).

Learn More:

JavaScript Numbers Tutorial

JavaScript Number Methods

JavaScript Number Properties

JavaScript Number Reference

JavaScript BigInt

Formula

All JavaScript numbers are stored in a 64 - bit floating - point format.

JavaScript BigInt is a new datatype (

Es2020

) that can be used to store integer values that are too big to be represented by a normal JavaScript Number.

Previous

JavaScript Code Blocks

Next

JavaScript Best Practices