bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/JavaScript/Debugging, Projects, and Reference
JavaScript•Debugging, Projects, and Reference

ECMAScript 2017

New Features in JavaScript 2017

FeatureDescription
String padStart()Pads the beginning of a string
String padEnd()Pads the end of a string
Object entries()Returns an array of the key/value pairs of an object
Object values()Returns an array of the values of an object
async and awaitSimplifies the handling of promises
Trailing CommasAllows trailing commas where a comma-separated list of values is accepted
getOwnProperty DescriptorsReturns an object containing all own property descriptors of an object

Browser Support

JavaScript 2017 is supported in all modern browsers since September 2017 :

Chrome 58Edge 15Firefox 52Safari 11Opera 45
Apr 2017Apr 2017Mar 2017Sep 2017May 2017

JavaScript String Padding

ECMAScript 2017 added two string methods to JavaScript: padStart() and padEnd() to support padding at the beginning and at the end of a string.

Examples

let text = "5";
text = text.padStart(4,0);

JavaScript Object Entries

ECMAScript 2017 added the Object.entries() method to objects.

Object.entries() returns an array of the key/value pairs in an object:

Example

const person = {
  firstName : "John", lastName : "Doe", age : 50, eyeColor : "blue"
};
let text = Object.entries(person);

Object.entries() makes it simple to use objects in loops:

Example

const fruits = {Bananas:300, Oranges:200, Apples:500};
let text = "";
for (let [fruit, value] of Object.entries(fruits)) {
  text += fruit + ": " + value + "<br>";
}

Object.entries() also makes it simple to convert objects to maps:

Example

const fruits = {Bananas:300, Oranges:200, Apples:500};
const myMap = new Map(Object.entries(fruits));

JavaScript Object Values

Object.values() is similar to Object.entries() , but returns a single dimension array of the object values:

Example

const person = {
  firstName : "John", lastName : "Doe", age : 50, eyeColor : "blue"
};
let text = Object.values(person);

JavaScript Async Functions

Waiting for a Timeout

async function myDisplay() {
  let myPromise = new Promise(function(myResolve,  myReject) {
    setTimeout(function() { myResolve("I love You !!"); }, 3000);
  });
document.getElementById("demo").innerHTML = await myPromise;
}
myDisplay();

JavaScript Trailing Commas

JavaScript allows trailing commas wherever a comma-separated list of values is accepted.

In Array and Object Literals, Function Calls, Parameters, Imports and Exports.

Example

function myFunc(x,,,) {};
const myArr = [1,2,3,4,,,];
const myObj = {fname: John, age:50,,,};

The Object.getOwnPropertyDescriptor() Method

Object.getOwnPropertyDescriptors() returns all own property descriptors of a given object.

Example

const myProp = Object.getOwnPropertyNames(person);

Example

const myProp = Object.getOwnPropertyDescriptors(person);

A property descriptor is an object that describes all attributes of a property:

  • value: The property's value
  • writable: true if the property value can be changed
  • enumerable: true if the property will show up in loops (for...in, Object.keys())
  • configurable: true if the property descriptor can be changed or deleted
  • get: Function to get the property value (for accessor properties)
  • set: Function to set the property value (for accessor properties)

Object Cloning

The Object.getOwnPropertyDescriptors() is often used to clone objects while preserving getters, setters, and property attributes:

Example

const clone = Object.defineProperties({}, Object.getOwnPropertyDescriptors(person));

Previous

ECMAScript 2018

Next

ECMAScript 2016

This chapter

Overview
32

Lessons

180m

Read time

1. JavaScript Errors2. JavaScript Debugging3. JavaScript Statements4. Project - localStorage Counter5. ECMAScript 20266. JavaScript Silent Errors7. JavaScript Debugging Console8. JavaScript Reserved Words9. Project - Event Listener10. ECMAScript 202511. JavaScript Error Statements12. JavaScript Debugging Breakpoints13. JavaScript Operator Precedence14. Project - To-Do List15. ECMAScript 202416. JavaScript Debugging Errors17. Project - Modal Popup18. ECMAScript 202319. JavaScript Debugging Async20. Project - Form Validation21. ECMAScript 202222. ECMAScript 202123. ECMAScript 202024. ECMAScript 201925. ECMAScript 201826. ECMAScript 201727. ECMAScript 201628. Javascript 2015 (ES6)29. JavaScript 2009 (ES5)30. JavaScript 1999 (ES3)31. JavaScript Versions32. JavaScript History

On this page

New Features in JavaScript 2017Browser SupportJavaScript String PaddingJavaScript Object EntriesJavaScript Object ValuesJavaScript Async FunctionsJavaScript Trailing CommasThe Object.getOwnPropertyDescriptor() MethodObject Cloning