Code_JS
web vitals extension arr.at(-1) deep copy = immutiable = JSON.parse(JSON.stringify(obj)) == structuredClone(obj) import maps alllow you to define a bunch of js modules at once (front end) view transition api animation timeline - experimental
import json from './foo.json' assert { type: 'json' };
top level await
let importModule; if (shouldImport) { importModule = await import('./module.mjs'); }
export * as am from 'another-module'
stringVar.matchAll(/test([\w]+?),/g); or replaceAll('/', '|') > regex
phoneNumbers.replace(/\d{3}-\d{3}-\d{4}/g, (_, p1, p2, p3) => {return
${p1}-${p2}-${p3}
; });const result = func?.();
const item = array?.[0];
arr.at(-1) === arr[arr.length - 1)
arr.flat(2)
x2 ??= getNewValue(); - assign iff null or undefined
x2 &&= 'b'; - assign iff βtruthyβ
x2 ||= getNewValue(); - Assign iff false
tagged template literals: formatNumbers(strings, number){ return strings[0] + number.toFixed(2) + strings[1]; } -- console.log(formatNumbers
This is the value: ${0}, it's important.
); // This is the value: 0.00, it's important.
cosnt grouped by = Object.groupBy([{},{},{}], fn) toSorted -> keeps initial arr immutable
function fn(){ console.log(arguements) }
Thearguments
object contains all the parameters passed to the function but is not available in arrow functions....- In arrow functions, 'this' does not have its own binding but instead retains the value of this from the enclosing lexical context.
- object destructuring: assign to variables values extracted from a nested object const x=today.min and const y=today.max === const {today: {min: x,max: y } } = {today: { min: 10, max: 30} }
- url.searchParams.append(key, params[key]),
document.currentScript window.top data.color ||= "#745DDE";
const screenSizeQuery = window.matchMedia("(min-width: 550px)"); screenSizeQuery.addEventListener("change", handleScreenSizeChange);
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", e => { localStorage.setItem("theme", e.matches ? "dark" : "light")
Click here to copy