Ali The Expert


JavaScript Cheat Sheet that you should bookmark

JavaScript Cheat Sheet that you should bookmark

This is the Cheat Sheet of JavaScript. It contains explanations, code examples, basic and important operators, functions, principles, methods, and many more. It provides a good overview of the language.


JavaScript is a programming language that powers the dynamic behavior on most websites. Alongside HTML and CSS, it is a core technology that makes the web run.


The console.log() method is used to log or print messages to the console. It can also be used to print objects and other info.
console.log("Hi there!");
// Prints: Hi there!


Strings are a primitive data type. They are any grouping of characters (letters, spaces, numbers, or symbols) surrounded by single quotes ‘ or double quotes ” .
let single = 'Wheres my bandit hat?';
let double = "Wheres my bandit hat?";


Numbers are a primitive data type. They include the set of all integers and floating point numbers.
let amount = 6;
let price = 4.99;


Booleans are a primitive data type. They can be either true or false .
let lateToWork = true;
let isHoliday = false;


Null is a primitive data type. It represents the intentional absence of value. In code, it is represented as null.
let x = null;

Arithmetic Operators

JavaScript supports arithmetic operators for:

  • – addition
  • – subtraction
  • multiplication
  • / division
  • % modulo
// Addition
5 + 5;
// Subtraction
10 - 5;
// Multiplication
5 * 10;
// Division
10 / 5;
// Modulo
10 % 5;


The .length property of a string returns the number of characters that make up the string.
let message = "good nite";
// Prints: 9
// Prints: 5


Methods return information about an object, and are called by appending an instance with a period . , the method name, and parentheses.


Libraries contain methods that can be called by appending the library name with a period . , the method name, and a set of parentheses.


The Math.random() function returns a floating-point random number in the range from 0 (inclusive) up to but not including 1.
// Returns a number between 0 and 1


The Math.floor() function returns the largest integer less than or equal to the given number.
// Prints: 5

Single Line Comments

In JavaScript, single-line comments are created with two consecutive forward slashes // .
// This line will denote a comment

Multi-line Comments

In JavaScript, multi-line comments are created by surrounding the lines with /* at the beginning and */ at the end. Comments are good ways for a variety of reasons like explaining a code block or indicating some hints, etc.
The below configuration must be
changed before deployment.
let baseUrl = "";


A variable is a container for data that is stored in computer memory. It is referenced by a descriptive name that a programmer can call to assign a specific value and retrieve it.
// examples of variables
let name = "Tammy";
const found = false;
var age = 3;
console.log(name, found, age);
// Tammy, false, 3