JavaScript Cheat Sheet - Complete Reference Guide

Essential JavaScript syntax, methods, and concepts. Your quick reference guide to modern JavaScript development with our interactive JavaScript playground.

Interactive JavaScript Playground

Quick Reference
Variables
let name = "John";const age = 30;var oldWay = true;
Functions
function greet() {return "Hello!";}
const arrow = () => {return "Arrow!";}
Reference

JavaScript Complete Guide

What is JavaScript?

JavaScript is a versatile, high-level programming language that enables interactive web pages and is an essential part of web applications. It's one of the core technologies of the World Wide Web, alongside HTML and CSS.

Features of Our JavaScript Tool

  • Interactive Playground: Write and test JavaScript code in real-time
  • Comprehensive Reference: Complete guide to JavaScript syntax and methods
  • Live Execution: See your code results instantly
  • Modern ES6+ Features: Learn the latest JavaScript features
  • Best Practices: Guidelines for clean and efficient code
JavaScript

Complete JavaScript Reference

Essential JavaScript syntax, methods, and concepts. Your quick reference guide to modern JavaScript development.

Variables & Data Types

let variable = value;Block-scoped variable
const variable = value;Constant variable
var variable = value;Function-scoped variable
typeof variableGet variable type
String, Number, BooleanPrimitive types
null, undefinedNull and undefined values
Symbol, BigIntES6+ primitive types
Object, Array, FunctionReference types

Functions

function name() {}Function declaration
const fn = function() {}Function expression
const fn = () => {}Arrow function
function(a, b = 1) {}Default parameters
function(...args) {}Rest parameters
return value;Return statement
fn.call(this, args)Call function with context
fn.apply(this, [args])Apply function with array

Arrays

arr.push(item)Add to end
arr.pop()Remove from end
arr.unshift(item)Add to beginning
arr.shift()Remove from beginning
arr.slice(start, end)Extract portion
arr.map(fn)Transform elements
arr.filter(fn)Filter elements
arr.reduce(fn, initial)Reduce to single value
arr.find(fn)Find first match
arr.includes(item)Check if includes

Objects

const obj = {key: value}Object literal
obj.propertyDot notation access
obj['property']Bracket notation access
delete obj.propertyDelete property
Object.keys(obj)Get property names
Object.values(obj)Get property values
Object.entries(obj)Get key-value pairs
Object.assign(target, src)Copy properties

DOM Manipulation

document.getElementById(id)Get element by ID
document.querySelector(sel)Get first matching element
document.querySelectorAll(sel)Get all matching elements
element.textContentGet/set text content
element.innerHTMLGet/set HTML content
element.setAttribute(name, val)Set attribute
element.classList.add(class)Add CSS class
element.addEventListener(event, fn)Add event listener

ES6+ Features

const {a, b} = objObject destructuring
const [a, b] = arrArray destructuring
...arraySpread operator
`Hello ${name}`Template literals
class ClassName {}Class declaration
import {module} from 'file'ES6 imports
export {module}ES6 exports
async/awaitAsync functions

JavaScript Key Features & Concepts

Modern JavaScript (ES6+) includes many powerful features that make development more efficient and code more readable:

  • Dynamic Typing: Variables can hold values of any type
  • First-class Functions: Functions are treated as values
  • Prototype-based OOP: Object-oriented programming without classes
  • Event-driven Programming: Respond to user interactions and events
  • Asynchronous Programming: Promises and async/await for handling async operations
  • Rich Ecosystem: npm packages and modern frameworks like React, Vue, Angular
  • Universal Language: Runs in browsers and server-side with Node.js

JavaScript Best Practices

Follow these guidelines for clean and maintainable JavaScript code:

  • Use const and let: Prefer const for constants and let for variables
  • Write Pure Functions: Functions that don't modify external state
  • Use Arrow Functions: For shorter, cleaner function syntax
  • Handle Errors: Use try-catch blocks and proper error handling
  • Use Modern ES6+ Features: Destructuring, template literals, modules
  • Test Your Code: Use our interactive playground to test JavaScript