Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Scope JS Dates JS Temporal Dates JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Data Types JS Errors JS Conventions JS References JS ECMAScript 2026 JS Versions

JS HTML

JS HTML DOM JS Events JS Projects

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Built-In Objects

A JavaScript variable can be either a Primitive type or an Object type.

The Object data type can hold many different object types.

Datatypes

Examples

// Object
const person = {firstName:"John", lastName:"Doe"};

// Array Object
const cars = ["Saab", "Volvo", "BMW"];

// Date Object
const date = new Date("2022-03-25");

JavaScript Objects

JavaScript Objects represent complex data structures and functionalities beyond the primitive data types (string, number, boolean, null, undefined, symbol, bigint).

JavaScript objects are written with curly braces { }.

JavaScript objects contains a collection of different properties.

Object properties are written as name:value pairs, separated by commas.

Example

Create a person object with 4 properties: firstName, lastName, age and eyeColor:

const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
Try it Yourself »

Built-In Object Types

A JavaScript object can represent a JavScript object or a User defined object.

Built-in JavavaScript object types can be:

ObjectDescription
ArrayArray of values accessed by a numerical index
MapArray of key-value pairs where the keys can be of any data type
SetArray of values where each value can only appear once
WeakMapA type of Map with weak references to the stored objects.
WeakSetA type of Set with weak references to the stored objects.
MathAn object that provides math constants and functions like PI and random()
DateObject for working with dates and times
RegExpObject for working with regular expressions
ErrorObject represents error conditions during program execution
JSONObject with methods for parsing values between JSON and objects
PromiseObject representing the completion or failure of an asynchronous operation
Int8ArrayArray for storing fixed-size 8-bits integer values
Int16ArrayArray for storing fixed-size 16-bits integer values
Int32ArrayArray for storing fixed-size 32-bits integer values
Float16ArrayArray for storing fixed-size 16-bits floating-point values
Float32ArrayArray for storing fixed-size 32-bits floating-point values
Float64ArrayArray for storing fixed-size 64-bits floating-point values
BigInt64ArrayArray for storing fixed-size 64-bits big integer values


The typeof Operator

You can use the JavaScript typeof operator to find the type of a JavaScript variable.

The typeof operator returns the type of a variable or an expression:

Example

typeof ""             // Returns "string"
typeof "John"         // Returns "string"
typeof "John Doe"     // Returns "string"
Try it Yourself »

Example

typeof 0              // Returns "number"
typeof 314            // Returns "number"
typeof 3.14           // Returns "number"
typeof (3)            // Returns "number"
typeof (3 + 4)        // Returns "number"
Try it Yourself »

JavaScript Arrays

JavaScript arrays are a special type of JavaScript objects.

JavaScript arrays are written with square [ ] brackets.

Array items are separated by commas.

The following code declares (creates) an array called cars, containing three items (car names):

Example

const cars = ["Saab", "Volvo", "BMW"];
Try it Yourself »

Array indexes are zero-based, which means the first item is [0], second is [1], and so on.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->