JavaScript Cheat Sheet Expanded
JavaScript Cheat Sheet Expanded
1. Basic Syntax
console.log("Hello, World!");
2. Data Types
3. Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
== Equal to
=== Strict equal to
!= Not equal to
!== Strict not equal to
4. Control Statements
if (condition) {
// code block
} else {
// another code block
}
switch(expression) {
Java Cheat Sheet
case value1:
// code
break;
default:
// code
}
5. Loops
while (condition) {
// loop body
}
6. Functions
function add(a, b) {
return a + b;
}
class Animal {
constructor(name) {
this.name = name;
}
makeSound() {
console.log("Sound");
}
}
const dog = new Animal("Dog");
Java Cheat Sheet
dog.makeSound();
8. Error Handling
try {
let x = y + 10; // y is not defined
} catch (error) {
console.log("Error: " + error.message);
}
9. DOM Manipulation
10. Events
document.getElementById("btn").addEventListener("click", function() {
alert("Button Clicked!");
});