0% found this document useful (0 votes)
3 views37 pages

JavaScript Cheatsheet - Coders - Section

This document is a comprehensive cheat sheet for JavaScript, covering topics from basic syntax and control structures to advanced concepts like asynchronous programming and object-oriented JavaScript. It includes sections on variables, data types, functions, DOM manipulation, error handling, and best practices. The cheat sheet serves as a quick reference guide for developers to understand and utilize JavaScript effectively.

Uploaded by

sarveshkabir92
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)
3 views37 pages

JavaScript Cheatsheet - Coders - Section

This document is a comprehensive cheat sheet for JavaScript, covering topics from basic syntax and control structures to advanced concepts like asynchronous programming and object-oriented JavaScript. It includes sections on variables, data types, functions, DOM manipulation, error handling, and best practices. The cheat sheet serves as a quick reference guide for developers to understand and utilize JavaScript effectively.

Uploaded by

sarveshkabir92
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

JAVASCRIPT

CheatSheet
TABLE OF CONTENTS
1. Introduction to JavaScript
What is JavaScript?
Features of JavaScript
How JavaScript Works in the Browser
JavaScript vs Other Languages

2. Basic Syntax
Variables (var, let, const)
Data Types
Comments
Operators (Arithmetic, Assignment, Comparison, Logical)
Type Conversion & Coercion

3. Control Structures
if, else, else if
switch Statement
Ternary Operator

4. Loops and Iteration


for, while, do...while
for...in, for...of
Loop Control (break, continue)

5. Functions
Function Declaration & Expression
Arrow Functions
Parameters & Arguments
Default Parameters
Rest & Spread Operators
Callback Functions
IIFE (Immediately Invoked Function Expressions)

6. Scopes and Closures


Global vs Local Scope
Block Scope
Lexical Scope
Closures Explained
TABLE OF CONTENTS
7. Objects
Object Literals
Dot vs Bracket Notation
Object Methods
this Keyword
Object Destructuring
[Link](), [Link](), [Link]()

8. Arrays
Creating Arrays
Common Methods (push, pop, shift, unshift, splice, slice)
Array Iteration (forEach, map, filter, reduce, find, some, every)
Destructuring Arrays

9. Strings
String Methods (length, slice, substring, substr, replace, includes, split, trim)
Template Literals

10. Date and Time


Creating Date Objects
Getting and Setting Date Values
Formatting Dates

11. Math and Numbers


Math Object Methods
Number Methods
Random Numbers

12. DOM Manipulation


[Link](), querySelector(), etc.
Changing Text & HTML Content
Changing Styles
Event Listeners
Creating and Removing Elements

13. Events
Event Types (click, submit, keydown, etc.)
Event Object
Event Bubbling and Capturing
TABLE OF CONTENTS
14. Error Handling
try, catch, finally
throw Statement
Common JavaScript Errors

15. ES6+ Modern JavaScript


let and const
Arrow Functions
Template Literals
Destructuring
Spread and Rest Operators
for...of Loop
Default Parameters
Enhanced Object Literals
Optional Chaining (?.)
Nullish Coalescing Operator (??)

16. Asynchronous JavaScript


setTimeout() & setInterval()
Callbacks
Promises
async / await
Fetch API

17. Object-Oriented JavaScript


Constructor Functions
Prototypes
ES6 Classes
Inheritance

18. Modules
import & export
CommonJS vs ES Modules

19. Useful Built-in APIs


Console API
Local Storage / Session Storage
Geolocation API
Clipboard API
Web Storage API
TABLE OF CONTENTS
20. Regular Expressions (RegEx)
Syntax and Flags
Common RegEx Patterns

21. Debugging Tools


[Link](), [Link](), etc.
Browser DevTools Tips

22. Best Practices


Writing Clean Code
Naming Conventions
Avoiding Common Mistakes
1. INTRODUCTION TO JAVASCRIPT
1.1 What is JavaScript?
JavaScript is a programming language used to make websites interactive. It
adds functionality like animations, forms, and live updates—all in your
browser.

1.2 Features of JavaScript


Interpreted and lightweight
Runs directly in browsers
Event-driven and asynchronous
Dynamically typed
Works well with HTML and CSS

1.3 How JavaScript Works in the Browser


JavaScript runs in the browser using a JavaScript engine (e.g., V8 in
Chrome). It executes code line-by-line and supports asynchronous features
like API calls.

1.4 JavaScript vs Other Languages

Feature JavaScript Python C++

Runs in Browser ✅ Yes ❌ No ❌ No


Dynamic Typing ✅ Yes ✅ Yes ❌ No
Beginner-friendly ✅ Yes ✅ Yes ❌ No
2. BASIC SYNTAX
2.1 Variables (var, let, const)
var: old, function-scoped
let: block-scoped, modern
const: block-scoped, read-only

2.2 Data Types


String, Number, Boolean, Null, Undefined, Object, Symbol, BigInt

2.3 Comments
Example:

2.4 Operators
There are 4 Types of Operators in JavaScript:
Arithmetic Operators – for mathematical operations
Assignment Operators – to assign values to variables
Comparison Operators – to compare values
Logical Operators – to handle true/false logic
2.4.1 - Arithmetic Operators:
Used to perform basic mathematical operations.

Operator Description Example Result

+ Addition 5+2 7

- Subtraction May 2, 2025 3

* Multiplication 5*2 10

/ Division Oct 2, 2025 5

% Modulus (Remainder) 10 % 3 1
2. BASIC SYNTAX
2.4.1 - Arithmetic Operators:
📌 Note: + is also used for string concatenation:

2.4.2 - Assignment Operators


Used to assign values to variables.

Operator Description Example Equivalent

"=" Assign x = 10 -

+= Add and assign x += 5 x=x+5

-= Subtract and assign x -= 3 x=x-3

*= Multiply and assign x *= 2 x=x*2

/= Divide and assign x /= 2 x=x/2

%= Modulus and assign x %= 3 x=x%3

2.4.3 - Comparison Operators


Used to compare two values, returning a boolean (true or false).

Operator Description Example Result

== Equal (loose, type converts) 5 == "5" TRUE

=== Equal (strict, type checks) 5 === "5" FALSE

!= Not equal (loose) 5 != "5" FALSE

!== Not equal (strict) 5 !== "5" TRUE

> Greater than 10 > 5 TRUE

< Less than 3<5 TRUE

>= Greater than or equal 10 >= 10 TRUE

<= Less than or equal 5 <= 6 TRUE

📌 Tip: Use === and !== for safer comparisons.


2. BASIC SYNTAX
2.4.4 - Logical Operators
Used to combine or invert boolean expressions.

Operator Description Example Result

&& AND (both must be true) true && false FALSE

` ` OR (at least one is true)

! NOT (reverses boolean value) !true FALSE

Example:

2.5 Type Conversion & Coercion


Example:
3. CONTROL STRUCTURES
Control structures help your program make decisions and control the flow
based on conditions.

3.1 if, else, else if


The if statement is used to run code based on a condition.

✅ If score is 90 or more → "Excellent"


✅ Else if score is 50 or more → "Good job"
❌ Else → "Try again"
3.2 switch Statement
Used for checking multiple values of a variable.

Each “case” is a possible value.


“break” stops further checking.
“default” runs if no match is found.
3. CONTROL STRUCTURES
3.3 Ternary Operator
A shorter way to write if...else.

“?” means “if true”


“:” means “else”
4. LOOPS AND ITERATION
Loops help you repeat tasks easily.

4.1 for, while, do...while


for loop — repeats a block a fixed number of times

while loop — runs while a condition is true

do...while loop — runs at least once

4.2 for...in, for...of


for...in — loops through object keys

for...of — loops through array values


4. LOOPS AND ITERATION
4.3 Loop Control (break, continue)
break: exits the loop completely
continue: skips to the next iteration
5. FUNCTIONS
Functions are blocks of code that perform a task. They help reuse code.

5.1 Function Declaration & Expression


Function Declaration

Function Expression

5.2 Arrow Functions


A shorter syntax for functions.

If only one parameter:

5.3 Parameters & Arguments


Parameters are like variables in the function.
Arguments are actual values you pass in.
5. FUNCTIONS
5.4 Default Parameters
Set a default value if no argument is passed.

5.5 Rest & Spread Operators


Rest (...) — for gathering values

Spread (...) — for spreading values

5.6 Callback Functions


A function passed as an argument to another function.

5.7 IIFE (Immediately Invoked Function Expression)


Runs immediately after it’s defined.
6. SCOPES AND CLOSURES
6.1 Global vs Local Scope
Variables declared outside functions are global; inside functions,
they are local.

6.2 Block Scope


let and const create block-level variables that only exist within {}.

6.3 Lexical Scope


Inner functions can access variables from their outer functions.
6. SCOPES AND CLOSURES
6.4 Closures Explained
A function that remembers its outer variables even after the outer
function is done.
7. OBJECTS
7.1 Object Literals
Objects are collections of key-value pairs.

7.2 Dot vs Bracket Notation


Use dot ([Link]) or bracket (obj["key"]) to access object properties.

7.3 Object Methods


Functions inside objects that define behavior.

7.4 this Keyword


Refers to the object that is calling the method.

7.5 Object Destructuring


Extract values from an object into variables easily.
7. OBJECTS
7.6 Object Utility Methods
Get keys, values, or key-value pairs using built-in methods.
8. ARRAYS
8.1 Creating Arrays
Use [] to create a list of values.

8.2 Common Methods


Add/remove elements or extract parts of an array.

8.3 Array Iteration


Loop over arrays using forEach, map, filter, etc.

8.4 Destructuring Arrays


Easily unpack array values into variables.
9. STRINGS
9.1 String Methods
Built-in methods to manipulate and inspect strings.

9.2 Template Literals


Use backticks ` and ${} for cleaner string formatting.
10. DATE AND TIME
10.1 Creating Date Objects
Use new Date() to get current or specific dates.

10.2 Getting and Setting Date Values


Use methods like getFullYear(), setDate(), etc. to work with dates.

10.3 Formatting Dates


Convert date objects to readable formats using toDateString() and
others.
11. MATH AND NUMBERS
11.1 Math Object Methods
Provides built-in math functions like rounding, power, etc.

11.2 Number Methods


Help format and convert numbers.

11.3 Random Numbers


Generate random values.
12. DOM MANIPULATION
12.1 Selecting Elements
Use built-in methods to access HTML elements.

12.2 Changing Text & HTML Content


Modify content dynamically.

12.3 Changing Styles


Apply CSS using JavaScript.

12.4 Event Listeners


React to user actions.

12.5 Creating and Removing Elements


Dynamically manage HTML structure.
13. EVENTS
13.1 Event Types
Common user-driven events.

13.2 Event Object


Provides data about the event.

13.3 Event Bubbling and Capturing


Controls event flow through elements.
14. ERROR HANDLING
14.1 try, catch, finally
Handle runtime errors safely.

14.2 throw Statement


Manually trigger an error.

14.3 Common JavaScript Errors


ReferenceError: using undefined variable
TypeError: using value in the wrong way
SyntaxError: incorrect code structure
15. ES6+ MODERN JAVASCRIPT
15.1 let and const
Block-scoped variable declarations.

15.2 Arrow Functions


Shorter syntax for functions.

15.3 Template Literals


Embed variables in strings using backticks.

15.4 Destructuring
Unpack values from arrays or objects.

15.5 Spread and Rest Operators

15.6 for...of Loop


Iterate over iterable objects.
15. ES6+ MODERN JAVASCRIPT
15.7 Default Parameters
Set default values for function parameters.

15.8 Enhanced Object Literals


Simplified syntax for object properties and methods.

15.9 Optional Chaining (?.)


Safely access deeply nested properties.

15.10 Nullish Coalescing (??)


Returns right-hand value only if left-hand is null or undefined.
16. ASYNCHRONOUS JAVASCRIPT
16.1 setTimeout() & setInterval()
Delay or repeat function execution.

16.2 Callbacks
Functions passed as arguments to be executed later.

16.3 Promises
Handle asynchronous operations with then and catch.

16.4 async / await


Syntactic sugar over Promises for cleaner code.
16. ASYNCHRONOUS JAVASCRIPT
16.5 Fetch API
Make HTTP requests in modern JavaScript.
17. OBJECT-ORIENTED JAVASCRIPT
17.1 Constructor Functions
Create objects using function templates.

17.2 Prototypes
Add methods to all instances of a constructor.

17.3 ES6 Classes


Cleaner syntax for object-oriented patterns.

17.4 Inheritance
Extend classes for reusability.
18. MODULES
18.1 import & export
Split code across files and reuse with modules.

18.2 CommonJS vs ES Modules


CommonJS: used in [Link] (require, [Link])
ES Modules: modern browsers and JS (import, export)
19. USEFUL BUILT-IN APIS
19.1 Console API
Used for debugging output.

19.2 Local Storage / Session Storage


Store data in the browser.

19.3 Geolocation API


Access user's location.

19.4 Clipboard API


Copy/paste text via code.

19.5 Web Storage API


Web APIs for local/session storage operations.
20. REGULAR EXPRESSIONS (REGEX)
20.1 Syntax and Flags
Patterns for matching strings.

20.2 Common RegEx Patterns


Example:
21. DEBUGGING TOOLS
21.1 [Link](), [Link](), etc.
Used to print values or trace issues.

21.2 Browser DevTools Tips


Use built-in tools in browsers like Chrome to inspect HTML, debug JS, and
monitor network activity.
Use Sources tab for step-by-step debugging.
Use Network tab to track API calls.
Use Elements tab to inspect DOM.
Add breakpoints and watch expressions.
22. BEST PRACTICES
22.1 Writing Clean Code
Keep code readable and organized.
Break code into reusable functions.
Comment only when necessary.

22.2 Naming Conventions


Use clear and consistent variable/function names.

22.3 Avoiding Common Mistakes


Use === instead of ==.
Avoid global variables.
Don’t forget break in switch.
Always handle asynchronous errors.
Was this post helpful ?

Follow Our 2nd Account

Follow For More


Tap Here

You might also like