Javascript Cheat Sheet

Discover the ultimate JavaScript cheat sheet! This quick reference guide covers essential concepts, syntax, and functions for all skill levels. Simplify coding

Introduction
Comments
// Single line comment/* Multi-line comment*/
Var Keyword
var name = "John";
Const Keyword
const pi = 3.14;
Console
console.log("Hello, World!");
Let Keyword
let age = 25;
Variables
let name = "John";
Numbers
let x = 5;let y = 3.14;
Strings
let greeting = "Hello, World!";
Scopes
Block Scope
if (true) { let x = 5; // Block scope}
Global Scope
var x = 5; // Global scope
Function Scope
function myFunction() { var x = 5; // Function scope}
Operators
Arithmetic Operators
let x = 5 + 2; // Additionlet y = 5 - 2; // Subtraction
Assignment Operators
let x = 5;x += 2; // x = x + 2
Comparison Operators
let isEqual = (5 == 5); // true
Ternary Operators
let result = (5 > 2) ? "True" : "False";
Logical Operators
let and = true && false; // false
Bitwise Operators
let bitwiseAnd = 5 & 1; // 1
Conditionals
If-Else Statement
if (true) { // code} else { // code}
Else-If Statement
if (x > 10) { // code} else if (x > 5) { // code} else { // code}
Switch Statement
switch (x) { case 1: // code break; case 2: // code break; default: // code}
Loops
For Loop
for (let i = 0; i < 5; i++) { // code}
Continue
for (let i = 0; i < 5; i++) { if (i === 2) { continue; } // code}
Break
for (let i = 0; i < 5; i++) { if (i === 2) { break; } // code}
While Loop
let i = 0;while (i < 5) { // code i++;}
For...In Loop
let object = {a: 1, b: 2};for (let key in object) { // code}
Do...While Loop
let i = 0;do { // code i++;} while (i < 5);
For...Of Loop
let array = [1, 2, 3];for (let value of array) { // code}
Arrays
Arrays and Index
let array = [1, 2, 3];console.log(array[0]); // 1
.Concat() Method
let newArray = array.concat([4, 5]);
.Push() Method
array.push(4);
.Fill() Method
array.fill(0);
.Pop() Method
array.pop();
.Reverse() Method
array.reverse();
Functions
Declaring And Calling Function
function myFunction() { // code}myFunction();
Function With Parameter
function myFunction(param) { // code}myFunction("argument");
Return Keyword
function add(a, b) { return a + b;}
Objects
Object
let object = { key: "value"};
Dot Notation
object.key = "new value";
Bracket Notation
object["key"] = "new value";
Classes
Class
class MyClass { constructor() { // code }}
Class Methods
class MyClass { myMethod() { // code }}
Iterators
Iterator
let iterator = array[Symbol.iterator]();
next() Method
iterator.next();
Modules
Modules
import { myFunction } from './myModule';
Export Multiple Objects
export { myFunction, myVariable };
Promises
Promises
let promise = new Promise((resolve, reject) => { // code});
Catch() Method
promise.catch(error => { // code});
Finally() Method
promise.finally(() => { // code});
Async - Await
Async Function
async function myFunction() { // code}
Await Keyword
let result = await myFunction();

Shortcut Keys