JavaScript Notes (Basic to Advanced)
1. Introduction to JavaScript
JavaScript is a lightweight, interpreted, or JIT-compiled programming language with first-class functions. It is primarily
used for client-side web development.
2. Data Types
Primitive: string, number, boolean, null, undefined, symbol, bigint
Non-Primitive: object, array, function
3. Variables
`var` is function-scoped and hoisted.
`let` and `const` are block-scoped and not hoisted.
4. Operators
Arithmetic: +, -, *, /, %, **
Comparison: ==, ===, !=, !==, >, <
Logical: &&, ||, !
Ternary: condition ? val1 : val2
5. Control Flow
if, else if, else
switch-case
Loops: for, while, do-while, for...in, for...of
6. Functions
Function declaration, function expression, arrow functions.
IIFE: (function() { ... })();
7. Objects
Objects hold key-value pairs. Use `this` to refer to the current object.
Methods can be added as properties.
8. Arrays
Common methods: push, pop, shift, unshift, map, filter, reduce, forEach, find.
9. DOM Manipulation
[Link](), querySelector(), innerHTML, textContent, style, classList.
10. Events
addEventListener() to attach events. Event types: click, mouseover, keypress, etc.
JavaScript Notes (Basic to Advanced)
11. ES6+ Features
let, const, arrow functions, template literals, destructuring, spread/rest, default params.
12. Asynchronous JavaScript
Callbacks, Promises, async/await.
Promises handle async tasks and avoid callback hell.
13. Error Handling
try...catch...finally block is used for handling errors gracefully.
14. Hoisting
Variables and functions declarations are hoisted to the top of their scope.
15. Closures
Functions have access to variables from their outer scope, even after the outer function returns.
16. `this` Keyword
`this` refers to the object from which the function was called. Arrow functions inherit `this` from their parent.
17. Local Storage
[Link](), getItem(), removeItem(), clear(). Used to store data in the browser.
18. JSON
Use [Link]() to convert object to JSON string.
Use [Link]() to convert JSON string to object.
19. Modules
Use export/import to reuse code across files.
export const x = 10; import { x } from './[Link]';
20. Best Practices
Use `const` by default. Use `let` if reassignment is needed.
Keep code DRY (Don't Repeat Yourself). Use comments and consistent naming.