This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sourceCode = "{data: 'Hello, \u2028World'}"; | |
eval(sourceCode) // 'Hello, World' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
someFunc() // thorws Error | |
} catch { | |
console.log('Error occurs') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sourceCode = "{data: 'Hello, \u2028World'}"; | |
eval(sourceCode) // SyntaxError: Invalid or unexpected token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default () => { | |
console.log("default export") | |
} | |
export function printArg(arg) { | |
console.log(arg) | |
} | |
export function throwError() { | |
throw Error("error!"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(2 ** 53) | |
// 9007199254740992 | |
console.log(2 ** 53 + 1) | |
// 9007199254740992 | |
console.log(2n ** 53n + 1n) | |
// 9007199254740993n | |
console.log(2n ** 53n * 1000n) | |
// 9007199254740992000n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const promise1 = Promise.resolve('foo'); | |
const promise2 = Promise.reject('bar') | |
const promises = [promise1, promise2]; | |
Promise.allSettled(promises). | |
then((results) => { | |
for (const result of results) { | |
if (result.status === 'fulfilled') console.log(result.value, 'is fulfilled'); | |
if (result.status === 'rejected') console.log(result.reason, 'is rejected'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let regexp = /t(e)(st(\d?))/g; | |
let str = 'test1test2'; | |
str.match(regexp); | |
// Array ['test1', 'test2'] | |
let array = [...str.matchAll(regexp)]; | |
console.log(array[0]); | |
// Array ["test1", "e", "st1", "1"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const label = 'test'; | |
console.time(label); | |
setTimeout(() => { | |
console.timeEnd(label); | |
}, 3000); | |
// 3001.732ms v12 | |
// 3.001s v13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const january = new Date(9e8); | |
const spanish = new Intl.DateTimeFormat('es', { month: 'long' }); | |
console.log(spanish.format(january)) | |
// 'M01' v12 | |
// 'enero` v13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// v12 | |
const assert = require('assert'); | |
const SomeError = class extends Error{}; | |
try { | |
// 第一引数でthrowされたエラーがSomeErrorか判定 | |
assert.throws(() => {throw new TypeError({})}, SomeError) | |
} catch (e) { | |
// eはTypeError | |
assert.ok(e instanceof TypeError) |