value. It does not mean the value it holds is immutable, just that the variable identi er cannot be reassigned. Constants can be declared with uppercase or lowercase, but a common convention is to use all- uppercase letters.
a: 1, b: 2 }; let { a: a_var, b: b_var } = obj // assign returning object from a function let { st_par, nd_par } = getParams() // Default params var list = [ 7, 42 ] var [ a = 1, b, d = 0 ] = list ES5 var obj = { a: 1, b: 2 }; var a_var = obj.a; var b_var = obj.b; var _getParams = getParams(); var st_par = _getParams.st_par; var nd_par = _getParams.nd_par; var list = [7, 42]; var _list$ = list[0]; var a = _list$ === undefined ? 1 : _list$; var _list$2 = list[1]; var b = _list$2 === undefined ? 2 : _list$2; var d = list[2]; console.log(a, b, d) // 7, 42, 0
=> a + b ES5 var my_func = function my_func(a, b) { var a = arguments.length <= 0 || arguments[0] === undefined ? 2 : arguments var b = arguments[1]; return a + b; };
user = { name: "Filippo" } let cart = { amount: 7 } let message = `Hello ${user.name}, your cart total is ${cart.amount} $` // Hello Filippo, // your cart total is 7 $ ES5 var user = { name: "Foo" }; var cart = { amount: 7 }; var message = "Hello " + user.name + ",\nyour cart total is " + cart.amount +
function called next() that returns an object with two properties: value (current) and done (if iteration finished). let fibonacci = { [Symbol.iterator]() { let pre = 0, cur = 1 return { next () { [ pre, cur ] = [ cur, pre + cur ] return { done: false, value: cur } } } } } // for..of operator for (let n of fibonacci) { if (n > 100) break
x + y } export var pi = 3.141593 // someApp.js import * as math from "lib/math" console.log("2π = " + math.sum(math.pi, math.pi)) // otherApp.js import { sum, pi } from "lib/math" console.log("2π = " + sum(pi, pi)) // lib/mathplusplus.js export * from "lib/math" export var e = 2.71828182846
computations. A Promise represents an operation that hasn't completed yet, but is expected in the future. A Promise is in one of these states: pending: initial state, not ful lled or rejected. ful lled: meaning that the operation completed successfully. rejected: meaning that the operation failed.