Skip to content

JavaScript Language Reference

This comprehensive reference covers the complete JavaScript language specification, from basic syntax to advanced features.

  • Array Grouping
  • Promise.withResolvers()
  • Regular Expression v flag
  • Atomics.waitAsync()
  • Array.findLast() and findLastIndex()
  • Hashbang Grammar
  • Symbols as WeakMap keys
  • Change Array by copy methods
  • Top-level await
  • Private class fields
  • Static class fields
  • RegExp match indices
  • Array.at() method
  • String.replaceAll()
  • Promise.any()
  • Logical assignment operators
  • Numeric separators
  • WeakRefs and FinalizationRegistry
  • BigInt primitive type
  • Optional chaining (?.)
  • Nullish coalescing (??)
  • Dynamic imports
  • globalThis object
  • Array.flat() and flatMap()
  • Object.fromEntries()
  • String.trimStart() and trimEnd()
  • Optional catch binding
  • Symbol.description
  • Async iteration
  • Rest/spread for objects
  • Promise.finally()
  • RegExp improvements
  • Template literal revision
  • Async functions
  • Shared memory and atomics
  • Object.values() and entries()
  • String padding methods
  • Object.getOwnPropertyDescriptors()
  • Exponentiation operator (**)
  • Array.includes()
  • Classes
  • Modules
  • Arrow functions
  • Template literals
  • Destructuring
  • Default parameters
  • Rest and spread
  • let and const
  • Promises
  • Maps and Sets
  • Symbols
  • Iterators and generators
// Understanding garbage collection
let obj = { data: new Array(1000000) };
obj = null; // Makes object eligible for GC
// WeakMap for memory-conscious caching
const cache = new WeakMap();
function expensiveOperation(obj) {
if (cache.has(obj)) {
return cache.get(obj);
}
const result = /* expensive computation */;
cache.set(obj, result);
return result;
}
// Avoid creating functions in loops
// Bad
for (let i = 0; i < items.length; i++) {
items[i].addEventListener('click', function() {
console.log(i);
});
}
// Good
function handleClick(index) {
return function() {
console.log(index);
};
}
for (let i = 0; i < items.length; i++) {
items[i].addEventListener('click', handleClick(i));
}
// Proxies for advanced object behavior
const target = {};
const proxy = new Proxy(target, {
get(obj, prop) {
return prop in obj ? obj[prop] : `Property ${prop} doesn't exist`;
},
set(obj, prop, value) {
if (typeof value === 'string') {
obj[prop] = value.toUpperCase();
} else {
obj[prop] = value;
}
return true;
}
});
// Reflect for meta operations
const obj = { a: 1 };
console.log(Reflect.has(obj, 'a')); // true
Reflect.set(obj, 'b', 2);
console.log(Reflect.ownKeys(obj)); // ['a', 'b']
// Understanding 'this' binding
const obj = {
name: 'Object',
method() {
console.log(this.name); // 'Object'
const arrow = () => {
console.log(this.name); // 'Object' (inherits from method)
};
function regular() {
console.log(this.name); // undefined (strict mode)
}
arrow();
regular();
}
};
// Understanding implicit conversions
console.log('' + 1); // '1' (string)
console.log(+'123'); // 123 (number)
console.log(!!'hello'); // true (boolean)
console.log([] + []); // '' (empty string)
console.log({} + []); // '[object Object]'
console.log(null == undefined); // true
console.log(null === undefined); // false
// Check for feature support
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
if (typeof Promise !== 'undefined') {
// Use Promises
} else {
// Use polyfill or fallback
}
// Modern feature detection
const supportsOptionalChaining = (() => {
try {
new Function('return obj?.prop')();
return true;
} catch {
return false;
}
})();
// Example polyfill for Array.includes()
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement, fromIndex) {
return this.indexOf(searchElement, fromIndex) !== -1;
};
}
utils.js
// Use modules for organization
export const formatDate = date =>
new Intl.DateTimeFormat('en-US').format(date);
export const debounce = (fn, delay) => {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn.apply(this, args), delay);
};
};
// main.js
import { formatDate, debounce } from './utils.js';
// Comprehensive error handling
class CustomError extends Error {
constructor(message, code) {
super(message);
this.name = 'CustomError';
this.code = code;
}
}
async function robustOperation() {
try {
const result = await riskyOperation();
return result;
} catch (error) {
if (error instanceof CustomError) {
console.error(`Custom error ${error.code}: ${error.message}`);
} else if (error instanceof TypeError) {
console.error('Type error:', error.message);
} else {
console.error('Unexpected error:', error);
}
throw error; // Re-throw if needed
}
}
// Advanced console usage
console.log('Basic log');
console.warn('Warning message');
console.error('Error message');
console.info('Info message');
// Grouping
console.group('User Details');
console.log('Name: John');
console.log('Age: 30');
console.groupEnd();
// Tables
console.table([
{ name: 'Alice', age: 25 },
{ name: 'Bob', age: 30 }
]);
// Timing
console.time('operation');
// ... some operation
console.timeEnd('operation');
// Assertions
console.assert(1 === 1, 'This will not show');
console.assert(1 === 2, 'This will show as error');
// Debugger statement
function complexFunction(data) {
debugger; // Execution will pause here when DevTools is open
return data.map(item => item * 2);
}
// Stack traces
function a() { b(); }
function b() { c(); }
function c() { console.trace('Call stack'); }
a();

This reference is continuously updated to reflect the latest JavaScript specifications and best practices. Use the search function to quickly find specific topics.