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

JavaScript Cheat Sheet Expanded

This document is a cheat sheet for JavaScript, covering basic syntax, data types, operators, control statements, loops, functions, objects and classes, error handling, DOM manipulation, and events. It provides examples for each topic, such as logging to the console, defining functions, and handling errors. The cheat sheet serves as a quick reference for essential JavaScript concepts and code snippets.

Uploaded by

raghubirkar11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

JavaScript Cheat Sheet Expanded

This document is a cheat sheet for JavaScript, covering basic syntax, data types, operators, control statements, loops, functions, objects and classes, error handling, DOM manipulation, and events. It provides examples for each topic, such as logging to the console, defining functions, and handling errors. The cheat sheet serves as a quick reference for essential JavaScript concepts and code snippets.

Uploaded by

raghubirkar11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Cheat Sheet

JavaScript Cheat Sheet

1. Basic Syntax

console.log("Hello, World!");

2. Data Types

Number - Integer and float (e.g., 10, 10.5)


String - Text (e.g., "Hello")
Boolean - true or false
Array - Collection of values (e.g., [1,2,3])
Object - Key-value pairs (e.g., {name: "John", age: 30})

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

for (let i = 0; i < 10; i++) {


console.log(i);
}

while (condition) {
// loop body
}

6. Functions

function add(a, b) {
return a + b;
}

const multiply = (a, b) => a * b;

7. Objects & Classes

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

document.getElementById("myElement").innerHTML = "New Text";


document.querySelector("#myElement").style.color = "red";

10. Events

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

You might also like