as math from './math' import secrets from './secrets' console.log(sum(PI, 4)) console.log(math.PI) console.log(secrets) // 7.141 // 3.141 // [‘hello’, 123] // math.js export function sum(x, y) { return x + y } export var PI = 3.141 // secrets.js export default const [ 'hello', 123 ]
=> { return s.replace(/(\r\n|\n|\r)\s*/gm, ' ').trim() }) let res = '' clean.forEach((val, i) => { res += val + (values[i] || '') }) return res } log(TAG` A more interesting way of removing line breaks (${1 + 1}). `)
// 2 log(s.has(‘second')) // true log(Array.from(s)) // [‘first’, ‘second’] // Map const m = new Map() m.set('first', 42) m.set(s, s.size) log(Array.from(m)) // [[‘first’, 42], [{}, 2]] log('The size of s is %s.', m.get(s)) // The size of s is 2.
42}) log('Size of the weak set: %s', ws.size) // Size of the weak set: undefined // Weak Map const wm = new WeakMap() wm.set(s, {secret: '123'}) log('Size of the weak map: %s', wm.size) // Size of the weak map: undefined
yield [key, obj[key]] } } const toys = {car: 100, pc: 2000, laptop: 500} const it = objectEntries(toys) log(it.next()) // { value: [ 'car', 100 ], done: false } log(it.next()) // { value: [ 'pc', 2000 ], done: false } log(it.next()) // { value: [ 'laptop', 500 ], done: false } log(it.next()) // { value: undefined, done: true } for (let [key, value] of objectEntries(toys)) { log('The value of %s is $%s.', key, value) } // The value of car is $100. // The value of pc is $2000. // The value of laptop is $500.
(n <= 1) return acc return factorial(n - 1, n * acc) } // Stack overflow in most implementations // today, but safe on arbitrary inputs in eS6 log(factorial(100000))
%s', Number.isInteger(Infinity)) log('Is "NaN" a NaN?', Number.isNaN('NaN')) log('Hyperbolic arccosine of 3: %s', Math.acosh(3)) // Epsilon 2.220446049250313e-16 // Is infinity an integer? false // Is "NaN" a NaN? false // Hyperbolic arccosine of 3: 1.7627471740390859