JavaScript Complete Study Notes
1. Introduction to JavaScript
What is JS? A high-level, interpreted programming language for web development. Created in 1995
by Brendan Eich.
Uses: Client-side (browsers), server-side ([Link]), apps, games.
Key Features: Dynamic, object-oriented, functional, event-driven. Case-sensitive.
How to Run: Embed in HTML <script> tags or external files. Test in browser console (F12 in
Chrome).
2. Basic Syntax
Statements end with ; (optional but recommended).
Comments: // single line or /* multi-line */.
Example:
[Link]('Hello, World!'); // Output to console
3. Variables and Data Types
Variables: let (block-scoped), const (immutable), var (function-scoped, avoid).
Data Types:
Primitives: string, number, boolean, undefined, null, symbol, bigint.
Objects: Arrays, functions, etc.
Examples:
let name = 'Alice';
const age = 25;
let isStudent = true;
let hobbies = ['reading', 'coding'];
let person = { name: 'Bob', age: 30 };
4. Operators
Arithmetic: +, -, *, /, %, ** (exponent).
Comparison: == (loose), === (strict), !=, !==, <, >, <=, >=.
Logical: &&, ||, !.
Assignment: =, +=, -=, etc.
Example:
let a = 10, b = 5;
[Link](a + b);
[Link](a === b);
[Link](a > b && b < 10);
5. Control Structures
If-Else:
if (age >= 18) { [Link]('Adult'); } else { [Link]('Minor'); }
Switch:
switch (day) { case 'Monday': [Link]('Start of week'); break; default: [Link]('Other
day'); }
Loops:
For, While, Do-While examples.
6. Functions
Reusable code blocks.
Declaration: function funcName(params) { return value; }
Arrow Functions: const func = (params) => value.
Examples:
function greet(name) { return 'Hello, ' + name; }
[Link](greet('John'));
const add = (a, b) => a + b;
[Link](add(2, 3));
7. Arrays and Objects
Arrays: Ordered lists. Methods: push(), pop(), map(), filter().
Objects: Key-value pairs accessed with . or [].
Example:
let fruits = ['apple', 'banana'];
[Link]('cherry');
let upperFruits = [Link](f => [Link]());
let car = { brand: 'Toyota', year: 2020 };
[Link] = 'red';
8. DOM Manipulation
Interact with HTML elements using JS.
Select: [Link](), [Link]().
Modify: [Link], [Link].
Example:
let el = [Link]('demo');
[Link] = 'Updated!';
[Link] = 'blue';
9. Events
Handle user actions via addEventListener.
Example:
[Link]('btn').addEventListener('click', () => { alert('Clicked!'); });
10. Asynchronous JavaScript
Promises handle async operations.
Async/Await for cleaner code.
Fetch API for HTTP requests.
Examples:
let promise = new Promise(resolve => setTimeout(() => resolve('Done'), 1000));
[Link](result => [Link](result));
async function fetchData(){ let result = await promise; [Link](result); }
fetchData();
fetch('[Link] => [Link]()).then(data => [Link](data));
11. Error Handling
Try/Catch structure for handling errors.
Example:
try { throw new Error('Oops!'); } catch (error) { [Link]([Link]); } finally {
[Link]('Always runs'); }
12. ES6+ Features
Destructuring, Spread Operator, Template Literals, Modules, Classes.
Example:
class Animal { constructor(name){ [Link] = name; } speak(){ [Link](`${[Link]} makes
a sound`); } }
let dog = new Animal('Dog'); [Link]();
13. Complete Project Example: Simple Todo App
HTML:
<input id='task' placeholder='Add task'>
<button id='add'>Add</button>
<ul id='list'></ul>
JS:
let tasks = [];
[Link]('add').addEventListener('click', ()=>{
let task=[Link]('task').value;
if(task){ [Link](task); updateList(); [Link]('task').value=''; }
});
function updateList(){ let list=[Link]('list'); [Link]='';
[Link]((task,index)=>{ let li=[Link]('li'); [Link]=task;
[Link]('click',()=>{ [Link](index,1); updateList(); });
[Link](li); }); }
14. Best Practices
Use let/const over var.
Write modular, clean code.
Test in multiple browsers.
Use [Link]() and DevTools for debugging.
15. Resources
MDN Docs: [Link]/en-US/docs/Web/JavaScript
FreeCodeCamp: [Link]/learn/javascript-algorithms-and-data-structures
Book: 'Eloquent JavaScript' (free online).
Generated by ChatGPT | JavaScript Complete Study Notes | Practice regularly to master JS.