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 TOOLS

Basic JavaScript

JS Tutorial JS Introduction JS Where To JS Output

JS Syntax

JS Syntax JS Statements JS Comments JS Variables JS Let JS Const JS Types

JS Operators

JS Operators JS Arithmetic JS Assignment JS Comparisons JS Conditional JS If JS If Else JS Ternary JS Switch JS Booleans JS Logical

JS Loops

JS Loops JS Loop for JS Loop while JS Break JS Continue JS Control Flow

JS Strings

JS Strings JS String Templates JS String Methods JS String Search JS String Reference

JS Numbers

JS Numbers JS Number Methods JS Number Properties JS Number Reference JS Bitwise JS BigInt

JS Functions

Function Path Function Intro Function Invocation Function Parameters Function Returns Function Arguments Function Expressions Function Arrow Function Quiz

JS Objects

Object Path Object Intro Object Properties Object Methods Object this Object Display Object Constructors

JS Scope

JS Scope JS Code Blocks JS Hoisting JS Strict Mode

JS Dates

JS Dates JS Date Formats JS Date Get JS Date Set JS Date Methods

JS Arrays

JS Arrays JS Array Methods JS Array Search JS Array Sort JS Array Iterations JS Array Reference JS Array Const

JS Sets

JS Sets JS Set Methods JS Set Logic JS Set WeakSet JS Set Reference

JS Maps

JS Maps JS Map Methods JS Map WeakMap JS Map Reference

JS Iterations

JS Loops JS Iterables JS Iterators JS Generators

JS Math

JS Math JS Math Reference JS Math Random

JS RexExp

JS RegExp JS RegExp Flags JS RegExp Classes JS RegExp Metachars JS RegExp Assertions JS RegExp Quantifiers JS RegExp Patterns JS RegExp Objects JS RegExp Methods

JS Data Types

JS Destructuring JS Data Types JS Primitive Data JS Object Types JS typeof JS toString JS Type Conversion

JS Errors

JS Errors Intro JS Errors Silent JS Error Statements JS Error Object

JS Debugging

Debugging Intro Debugging Console Debugging Breakpoints Debugging Errors Debugging Async Debugging Reference

JS Conventions

JS Style Guide JS Best Practices JS Mistakes JS Performance

JS References

JS Statements JS Reserved Keywords JS Operators JS Precedence

JS Versions

JS 2026 JS 2025 JS 2024 JS 2023 JS 2022 JS 2021 JS 2020 JS 2019 JS 2018 JS 2017 JS 2016 JS Versions JS 2015 (ES6) JS 2009 (ES5) JS 1999 (ES3) JS IE / Edge JS History

JS HTML

JS HTML DOM JS Events JS Projects New

JS Advanced

JS Temporal  New 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


ECMAScript 2018


New Features in JavaScript 2018

FeatureDescription
Asynchronous Iteration Allows the await keyword in for/of loops
Promise Finally Schedules a function to be executed when a promise has been "fulfilled" or "rejected"
Array Rest Elements Allows to destruct an array and collect the leftovers
Object Rest Properties Allows to destruct an object and collect the leftovers
Shared Memory Allows different parts of a program to access the same memory

New RegExp Features in 2018

FeatureDescription
/s Allows the . (dot) metacharacter to match line terminators
\p{} Matches character with a Unicode character property
(?<=y) (?<=y)x matches "x" if "x" is preceded by "y"
(?<!y) (?<!y)x matches "x" if "x" is NOT preceded by "y"
(?<name>) Captures text and names (labels) it

Browser Support

ECMAScript 2018 is supported in all modern browsers since Jun 2020:

Chrome
64
Edge
79
Firefox
78
Safari
12
Opera
51
Jan 2018 Jan 2020 Jun 2020 Sep 2018 Feb 2018

JavaScript Asynchronous Iteration

ECMAScript 2018 added asynchronous iterators and iterables.

With asynchronous iterables, we can use the await keyword in for/of loops.

Example

for await () {}

JavaScript Promise.finally()

ECMAScript 2018 finalizes the full implementation of the Promise object with Promise.finally:

Promise.finally() defines a function to be executed when a promise has either been successfully resolved rejected.

Example

let myPromise = new Promise();

myPromise.then();
myPromise.catch();
myPromise.finally();

JavaScript Array Rest Elements

ECMAScript 2018 added the rest operator (...).

The rest operator (...) allows us to destruct an array and collect the leftovers:

Example 1

let a, rest;
const arr1 = [1,2,3,4,5,6,7,8];

[a, ...rest] = arr1;
Try it Yourself »

Example 2

let a, b, rest;
const arr1 = [1,2,3,4,5,6,7,8];

[a, b, ...rest] = arr1;
Try it Yourself »

JavaScript Object Rest Properties

ECMAScript 2018 added the rest operator (...).

This allows us to destruct an object and collect the leftovers onto a new object:

Example

// Create an Object:
const car = {type:"Fiat", model:"500", color:"white"};

// Destructure the Object
let {type, model, color} = car;
document.getElementById("demo").innerHTML = "The car type is: " + type;
Try it Yourself »


New JavaScript RegExp Features

ECMAScript 2018 added 4 new RegExp features:

  • /s (dotAll) Flag
  • Unicode Property Escapes (\p{...})
  • Lookbehind Assertions (?<=y)x and (?<!y)x
  • Named Capture Groups

RegExp /s Flag

Example

let text = "Line\nLine.";

let pattern = /Line./gs;
let result = text.match(pattern);
Try it Yourself »

Description

The s (dotAll) flag allows the . (dot) metacharacter to match any character, including line terminator characters (like \n, \r, \u2028, \u2029).

Without s, \n does not match line terminators.


RegExp \p Metacharacter

Example

let text = "Hello 😄";

let pattern = /\p{RGI_Emoji}/v;
let result = pattern.test(text);
Try it Yourself »

Description

The \p{Unicode Property} metacharacter matches any character with a Unicode character property.


RegExp Lookbehind

Example (?<=y)x

let text = "Hello W3Schools";

let pattern = /(?<=Hello )W3Schools/;
let result = pattern.test(text);
Try it Yourself »

Description

(?<=y)x matches "x" if "x" is preceded by "y".


Negative Lookbehind

Example (?<!y)x

let text = "Hello W3Schools";

let pattern = /(?<=Hello )W3Schools/;
let result = pattern.test(text);
Try it Yourself »

Description

(?<!y)x matches "x" if "x" is NOT preceded by "y".


RegExp Named Capturing Groups

Example (?<name>...)

const text = "Name: John Doe";

// Using named capturing groups
const regex = /(?<firstName>\w+) (?<lastName>\w+)/;
const match = text.match(regex);

let fName = match.groups.firstName;
let lName = match.groups.lastName;
Try it Yourself »

Explained

  • (?<firstName>\w+) captures a word and labels it firstName
  • (?<lastName>\w+) does the same for lastName
  • text.match() returns an array with a groups property
  • match.groups() returns an object:
    {firstName:"John", lastName:"Doe" }

When using a regular expression with capturing groups, the match() method of a string returns a result array that includes a groups property. This groups property is an object that holds the matches for named capturing groups.


JavaScript Threads

In JavaScript you use the Web Workers API to create threads.

Worker threads are used to execute code in the background so that the main program can continue execution.

Worker threads run simultaneously with the main program. Simultaneous execution of different parts of a program can be time-saving.

JavaScript Shared Memory

Shared memory is a feature that allows threads (different parts of a program) to access and update the same data in the same memory.

Instead of passing data between threads, you can pass a SharedArrayBuffer object that points to the memory where data is saved.

SharedArrayBuffer

A SharedArrayBuffer object represents a fixed-length raw binary data buffer similar to the ArrayBuffer object.


×

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.

-->