Javascript Cheatsheet

Console Logging

console.log() is a function that prints to the console.
console.info() outputs an informational message to the console.
console.error() outputs an error message to the console.
console.warn() outputs a warning message to the Web console.
console.debug() outputs a message to the web console at the "debug" log level. The message is only displayed to the user if the console is configured to display debug output. In most cases, the log level is configured within the console UI. This log level might correspond to the `Debug` or `Verbose` log level.
console.time(label) starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 10,000 timers running on a given page. When you call console.timeEnd() with the same name, the browser will output the time, in milliseconds, that elapsed since the timer was started.
console.timeLog(label) logs the current value of a timer that was previously started by calling console.time() to the console.
console.timeEnd(label) ends a timer. Once stopped, the elapsed time is automatically displayed in the Web console along with an indicator that the time has ended.

Promises

async & await Async functions can contain zero or more await expressions. Await expressions make promise-returning functions behave as though they're synchronous by suspending execution until the returned promise is fulfilled or rejected. The resolved value of the promise is treated as the return value of the await expression. Use of async and await enables the use of ordinary try / catch blocks around asynchronous code.
async function () { creates a new Promise object.
await promise The await expression causes async function execution to pause until a Promise is settled (that is, fulfilled or rejected), and to resume execution of the async function after fulfillment. When resumed, the value of the await expression is that of the fulfilled Promise.

If the Promise is rejected, the await expression throws the rejected value.

If the value of the expression following the await operator is not a Promise, it's converted to a resolved Promise.

An await splits execution flow, allowing the caller of the async function to resume execution. After the await defers the continuation of the async function, execution of subsequent statements ensues. If this await is the last expression executed by its function, execution continues by returning to the function's caller a pending Promise for completion of the await's function and resuming execution of that caller.

Scope await can only be used inside an async function.

Top Level Await

( async () => { await asyncFunction(); })(); The use of an IIFE allows the use of await in top level scope.