Javascript is one of the most popular programming languages used by web developers. This comprehensive cheat sheet will help you learn a little bit about it every day.
If you are a beginner or intermediate in javascript and want to learn javascript in a very simple manner, then you can go through the following javascript cheat sheet.
JavaScript is a programming language that is used to create client-side and server-side web applications. This cheat sheet for web developers explains the basic syntax of JavaScript.
JavaScript is a high-level, dynamic, and interpreted programming language that is frequently used to create dynamic websites and web applications.
A javascript cheat sheet can get you up to speed with the language and prevent you from making common beginner mistakes. This cheat sheet provides a solid foundation for any javascript developer.
The download link is at the button
Here is a basic JavaScript cheat sheet that you can use as a reference:
Variables
// Declare a variable
var x;
// Declare and assign a value to a variable
var y = 5;
// Declare and assign a value to a variable with type inference
let z = 'hello';
// Declare and assign a value to a variable with type inference (constant)
const a = [1, 2, 3];
Data Types
// Number
const num = 42;
// String
const str = 'hello';
// Boolean
const bool = true;
// Array
const arr = [1, 2, 3];
// Object
const obj = { a: 1, b: 2 };
// null
const nothing = null;
// undefined
let x;
Operators
// Arithmetic operators
let x = 5 + 5; // 10
x = 5 - 5; // 0
x = 5 * 5; // 25
x = 5 / 5; // 1
x = 5 % 5; //
// Assignment operators
x = 5; // x is 5
x += 5; // x is 10
x -= 5; // x is 5
x *= 5; // x is 25
x /= 5; // x is 5
x %= 5; // x is 0
// Comparison operators
x = 5;
x == 5; // true
x == '5'; // true
x === 5; // true
x === '5'; // false
x != 5; // false
x != '5'; // false
x !== 5; // false
x !== '5'; // true
x > 5; // false
x < 5; // false
x >= 5; // true
x <= 5; // true
// Logical operators
true && true; // true
true && false; // false
true || true; // true
true || false; // true
!true; // false
!false; // true
Control Structures
// if statement
if (x > 5) {
console.log('x is greater than 5');
} else if (x < 5) {
console.log('x is less than 5');
} else {
console.log('x is equal to 5');
}
// for loop
for (let i = 0; i < 5; i++) {
console.log(i);
}
// while loop
let i = 0;
while (i < 5) {
console.log(i);
i++;
}
// do-while loop
let i = 0;
do {
console.log(i);
i++;
} while (i < 5);
// switch statement
switch (x) {
case 1:
console.log('x is 1');
break;
case 2:
console.log('x is 2');
break;
default:
console.log('x is not 1 or 2');
break;
}
Functions
// Declare a function
function add(x,
sab@gmail.com
continue
y) {
return x + y;
}
// Call a function
const result = add(5, 5);
// Arrow function
const subtract = (x, y) => x - y;
const result = subtract(5, 5);
// Function with default parameters
const divide = (x, y = 2) => x / y;
const result = divide(5); // 2.5
// Function with rest parameters
const sum = (...numbers) => numbers.reduce((acc, x) => acc + x, 0);
const result = sum(1, 2, 3, 4, 5); // 15
// Function with a callback
const multiply = (x, y, callback) => callback(x * y);
multiply(5, 5, (result) => console.log(result)); // 25
## Objects
// Declare an object
const obj = {
x: 1,
y: 2,
z: 3,
};
// Access object properties
console.log(obj.x); // 1
console.log(obj['y']); // 2
// Add a property to an object
obj.w = 4;
// Remove a property from an object
delete obj.z;
// Iterate over object properties
for (const prop in obj) {
console.log(${prop}: ${obj[prop]});
}
## Arrays
// Declare an array
const arr = [1, 2, 3];
// Access an array element
console.log(arr[0]); // 1
// Add an element to the end of an array
arr.push(4);
// Remove an element from the end of an array
arr.pop();
// Iterate over an array
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
// Iterate over an array with forEach
arr.forEach((x) => console.log(x));
// Map an array to a new array
const double = arr.map((x) => x * 2);
// Filter an array
const even = arr.filter((x) => x % 2 === 0);
// Reduce an array
const sum = arr.reduce((acc, x) => acc + x, 0);
Also, check out these helpful JavaScript Post
Tags:
Resources