0% found this document useful (0 votes)
5 views

JavaScript_Cheat_Sheet

This JavaScript Cheat Sheet provides a quick reference to essential concepts including variables, data types, operators, functions, conditionals, loops, arrays, objects, DOM manipulation, events, JSON, and useful methods. It includes code snippets for each topic to illustrate usage. This resource is designed for quick lookups and to aid in learning JavaScript programming.

Uploaded by

kunal.g.2697
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JavaScript_Cheat_Sheet

This JavaScript Cheat Sheet provides a quick reference to essential concepts including variables, data types, operators, functions, conditionals, loops, arrays, objects, DOM manipulation, events, JSON, and useful methods. It includes code snippets for each topic to illustrate usage. This resource is designed for quick lookups and to aid in learning JavaScript programming.

Uploaded by

kunal.g.2697
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Cheat Sheet

1. Variables
var x = 10;
let y = 20;
const z = 30;

2. Data Types
Number: 42
String: "Hello"
Boolean: true / false
Array: [1, 2, 3]
Object: { name: "John", age: 25 }
Undefined, null

3. Operators
Arithmetic: +, -, *, /, %
Assignment: =, +=, -=
Comparison: ==, ===, !=, !==, >, <, >=, <=
Logical: &&, ||, !
Ternary: condition ? true : false

4. Functions
function greet(name) {
return "Hello " + name;
}

const greetArrow = (name) => "Hello " + name;

5. Conditionals
if (x > 0) {
console.log("Positive");
} else if (x === 0) {
console.log("Zero");
} else {
console.log("Negative");
}
JavaScript Cheat Sheet

6. Loops
for (let i = 0; i < 5; i++) {
console.log(i);
}

while (x < 10) {


x++;
}

7. Arrays
let nums = [1, 2, 3];
nums.push(4);
nums.pop();
nums.shift();
nums.unshift(0);
nums.forEach(n => console.log(n));

8. Objects
let person = {
name: "Alice",
age: 25,
greet: function() {
return "Hi " + this.name;
}
};

9. DOM Manipulation
document.getElementById("demo").innerHTML = "Hello";
document.querySelector("p").style.color = "red";

10. Events
document.getElementById("btn").addEventListener("click", function() {
alert("Clicked!");
});

11. JSON
JavaScript Cheat Sheet

let json = '{"name":"John"}';


let obj = JSON.parse(json);
let str = JSON.stringify(obj);

12. Useful Methods


String: length, toUpperCase(), split()
Array: map(), filter(), reduce()
Object: Object.keys(), Object.values()

You might also like