JavaScript by Example

JavaScript (JS) is a programming language and core technology of the Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.

JavaScript by Example is a hands-on introduction to JavaScript. Check out the first example or browse the full list below.

Unless stated otherwise, examples here assume the latest major release of Javacript and may use new language features.

Hello World

In JavaScript, `console.log` can be used to print anything to the console in a browser, or a terminal when running in a server-side environment like Node JS.

console.log("Hello, world!");

Comments

Variables

Data Types

If / Else

Switch

For Loops

Functions

Operators

Numbers

Dates & Time

Regular expressions

Arrays

Objects

Sets

Classes

Promises

Async / Await

Error handling