JavaScript Cheat Sheet for Quick Reference (Beginners Guide)

Emma Delaney
5 min readAug 31, 2023

A Javascript cheat sheet is a reference tool that provides quick and easy access to the language’s standard syntax and coding features. It can be used by novice programmers and experienced developers to quickly review basic concepts, find solutions to common problems, or research unfamiliar language features.

Introduction :

Comments

Comments can also be used to temporarily disable parts of a program so that the code can be tested and documented.

// This line will denote
a Single line comment

/* This line will denote
a Multi line comment */

Console

The console in JavaScript is used to record information as part of the debugging process.

// => Good Morning!
console.log('Good Morning!');

// => Good Morning!
console.warn('Good %s', 'Morning!');

// Prints error message to stderr
console.error(new Error('OH No!'));

Variables

Variables are names assigned to parts of a computer program and store values ​​that can change during program execution.

let a = 6;
let name = "Sandos";
const pieValue = 3.14;

// => 6, Rahul, 3.14
console.log(a, name, pieValue);

var b;
console.log(b); // => undefined

Let Keyword

let is a keyword in Javascript that declares a variable. It allows the variable to be available only in the current code block (or scope).

let a;
console.log(a); // => undefined

a = 6;
console.log(a); // => 6

Read More: JavaScript Works: An Overview Of The Engine, The Runtime, And The Call Stack

Scopes :

Block Scope

Block scope means that the variable is accessible only within the block in which it was declared, not from outside.

let bulb = true;
if (bulb == true) {
const bulbOn = 'Light On';
}
// Uncaught ReferenceError...
console.log(bulbOn);

Global Scope

Global scope is available throughout the program and can be accessed from any code in the program.

// Variable declared globally
const city = 'california';
function myCity() {
console.log(city);
}
myCity(); // California

Function Scope

Functional scope in JavaScript refers to the environment in which a function is declared and executed.

function myFunction() 
{
var country = "Usa";
// Code here can use country
}
// Code here can't use country

Operators :

Arithmetic Operators

Arithmetic operators in JavaScript are symbols that allow you to perform mathematical operations on one or more operands.

3 + 3 = 6     // Addition
6 - 3 = 3 // Subtraction
6 * 10 = 60 // Multiplication
6 / 3 = 2 // Division
10 % 6 = 0 // Modulus

let x = 5; // Increment
x++;
console.log(x); // 6

let x = 5; // Decrement
x--;
console.log(x); // 4

Comparison Operators

The comparison operators in JavaScript are used to compare two values ​​and determine whether the condition is true or false.

//equal to
a == 8 // false

//equal value and equal type
a === 5 //true

//not equal
a != 8 //true

//not equal value or not equal type
x !== 5 //false

//greater than
x > 8 //false

//less than
x < 8 //true

//greater than or equal to
x >= 5 //true

//less than or equal to
x <= 8 //true

Logical Operators

Logical operators are used in JavaScript to perform logical operations on values. Logical operators are often used with conditional statements to determine whether a given condition is true or false.

// Logical Operator ||                
10 > 3 || 9 > 20; // true
6 > 60 || 5 > 30; // false
true || false; // true
false || false; // false

// Logical Operator &&
1 > 6 && 6 > 1; // false
6 === 6 && 9 > 1; // true
true && true; // true
true && false; // false

// Logical Operator !
let officeWork = true;
let work = !officeWork;

// => false
console.log(work);

Arrays :

Arrays and Index

An array in Javascript is an object used to store multiple data in a single variable. Each value in the array can be accessed and manipulated via an indexed number called an index.

// Array
let language = ["Javascript", "Java", "Python"];
// Different data types
let newDataArray = ['Rajesh','Javascript',9];

// Index
console.log(language[0]); // Javascript
console.log(newDataArray[2]); // 9

.Push() Method

The Array.push() method in JavaScript adds one or more elements to the end of an array and returns the new backward array length.

// Array push() Method
let language = ["Javascript", "Java", "Python"];

// add "Php" to the array
language.push("Php");
console.log(language);

.Pop() Method

The Array.pop() is a JavaScript function that removes the last element from an array and returns that element. This function changes the length of the table.

// Array pop() Method
let language = ["Javascript", "Java", "Python","Php"];

// remove the last element
let removedlanguage = language.pop();

console.log(language) // ["Javascript", "Java", "Python","Php"]
console.log(removedlanguage); // Php

Functions :

Declaring And CallingFunction

In JavaScript, a function is a series of instructions that perform a specific task. The function can be called and executed on demand, and can also be declared or defined for a later call.

// declaring a function named demo()
function demo() {
console.log("Hello Javascript...!!");
}
//calling Function
demo();

Function With Parameter

In JavaScript, a function with one parameter is a function that can accept input values, called parameters or arguments, when called. These parameters are used as variables in the body of the function and can be used to perform calculations or operations within the function.

// declaring a function
function addition(a, b) {
console.log(a + b);
}
// calling functions
addition(3,6);

Return Keyword

The return keyword in JavaScript is used to stop the execution of a function and return a value from that function. Can be used to return a specific value or no value.

let x = myMulFunction(3, 9);   // Function is called, return value will end up in x

function myMulFunction(a, b) {
return a * b; // Function returns the product of a and b
// 27
}

Are you ready for interview, Do preparation for Javascript Interview Questions.

Must try my new extension and make your browser beautiful

Install Now

--

--