0% found this document useful (0 votes)
17 views49 pages

Web Programing

The document provides a comprehensive overview of JavaScript, covering its core identity, types, built-in objects, variables, functions, and key programming concepts such as prototype inheritance and higher-order functions. It highlights common misconceptions and traps related to JavaScript, along with important keywords and memory aids for better understanding. Additionally, it touches on advanced topics like ES6 features, the DOM, and debugging techniques.

Uploaded by

ankushkurkure19
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views49 pages

Web Programing

The document provides a comprehensive overview of JavaScript, covering its core identity, types, built-in objects, variables, functions, and key programming concepts such as prototype inheritance and higher-order functions. It highlights common misconceptions and traps related to JavaScript, along with important keywords and memory aids for better understanding. Additionally, it touches on advanced topics like ES6 features, the DOM, and debugging techniques.

Uploaded by

ankushkurkure19
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1️⃣ JavaScript – Core Identity (PDF + CCEE)

WHAT IS IT?

 Invented by Brendan Eich (1995, Netscape)

 Scripting language for web

 Interpreted / JIT

 Runs in:

o Browser

o Server ([Link])

✅ CDAC SAFE STATEMENT

JavaScript is a dynamically typed scripting language used for client-side and server-side
development.

🚨 CCEE TRAPS

❌ JavaScript = Java
❌ JavaScript needs JVM
❌ JavaScript is compiled like C++

🧠 KEYWORDS TO REMEMBER

Java = JVM
JavaScript = JS Engine

2️⃣ Types of JavaScript (PDF: Internal / External)

Internal JS

<script>

// JS code

</script>

 Written inside HTML

 Mostly for small scripts

External JS
<script src="[Link]"></script>

 Reusable

 Clean separation

 Preferred in real apps

🚨 CDAC TRAP
❌ External JS is mandatory
❌ Internal JS cannot access DOM

🧠 MEMORY LOGIC

Small → Internal
Big / reusable → External

3️⃣ Built-in Objects (PDF Order)

console

 Used for debugging

[Link]("hello");

window

 Browser object

 alert, prompt, confirm

document

 Represents DOM

 Used to access HTML elements

🚨 CDAC TRAP
❌ document = HTML
❌ DOM is part of HTML

✅ Truth:

DOM is created by browser, not HTML itself

4️⃣ Variables (VERY HIGH WEIGHT)

Definition
Variable = container to store data

JS Rule (IMPORTANT)

❗ Data type is NOT declared


JS decides type at runtime

var

 Function scoped

 Redeclaration allowed

 Hoisted (undefined)

let

 Block scoped

 No redeclaration

 Hoisted (TDZ)

const

 Block scoped

 Cannot reassign

 Value can change if object

🚨 PDF ERROR (IMPORTANT)


Your PDF says:

“var is deprecated”

❌ WRONG for exam


Correct:

var is not deprecated, but not recommended

🧠 MEMORY KEY

var = old
let = safe
const = fixed reference

5️⃣ Variable Scope (PDF Order)


Global

 Declared outside function

 Accessible everywhere

⚠️Without keyword = implicit global (VERY BAD)

Local

 Declared inside function

 Accessible only inside

🚨 CDAC TRAP
❌ let is function scoped
❌ var is block scoped

6️⃣ Data Types (PDF + Exam)

Primitive Types

 number

 string

 boolean

 undefined

 null

Special Values

 NaN

o Type = number

 Infinity

o Division by zero

🚨 CDAC FAVORITE

typeof NaN // number

🧠 MEMORY

NaN lies — it says it’s a number


7️⃣ Functions (VERY IMPORTANT)

Normal Function

function fun() {}

Function Alias

var f = fun;

Function Properties (PDF TRAPS)

✔ JS allows:

 Extra parameters

 Missing parameters

 Function call before definition (hoisting)

🚨 VERY IMPORTANT
If same function name appears multiple times →
👉 LAST definition is used

🧠 MEMORY

JS = flexible, not strict

8️⃣ Parameters & arguments

 JS does NOT enforce parameter count

 Missing → undefined

 Extra → ignored / arguments object

9️⃣ Hoisting (PDF IMPLIED, CDAC LOVES)

fun();

function fun() {}

✔ Works

f();

var f = function() {}

❌ Error
🧠 FINAL MEMORY RULE

function keyword hoists fully


function expression does NOT

🔥 BLOCK 4 (CONTINUED) — AS PER SIR’S PDF FLOW


Topic: Anonymous Function → Arrow Function → HOF → Hidden Params → Object

1️⃣ Anonymous Function

🔹 WHAT IS THIS?

A function without a name is called an anonymous function.

Example (PDF):

var multiply = function(p1, p2) {

[Link](p1 * p2);

Here:

 function(p1,p2){} → anonymous

 stored in variable multiply

🔹 WHY DOES THIS EXIST?

 Functions are first-class citizens

 Can be:

o stored in variables

o passed as arguments

o returned from functions

Anonymous functions make this possible.


🚨 CCEE TRAP ALERT

❌ Anonymous function cannot be reused


❌ Anonymous function cannot be assigned
❌ Anonymous function must be arrow

All false.

🧠 KEYWORD TO REMEMBER

No name + assigned = anonymous

2️⃣ Arrow Functions (ES6)

🔹 WHAT IS THIS?

Arrow function is a shorter syntax for function expression.

Example (PDF):

const add = (a, b) => {

return a + b;

🔹 SHORTCUT FOR SINGLE LINE

const square = x => x * x;

✔ No {}
✔ No return

🔹 RETURNING OBJECT (BIG TRAP)

const createObject = () => ({ message: "Hello" });

🚨 Without () → syntax error

🚨 CCEE TRAPS

❌ Arrow function has its own this


❌ Arrow function is hoisted like normal function
❌ Arrow function replaces all functions
Truth:

 Arrow functions do NOT have their own this

 Arrow functions are NOT hoisted

🧠 KEYWORD

Arrow = short + no own this

3️⃣ Higher Order Functions (HOF)

🔹 WHAT IS THIS?

A function that accepts another function OR returns a function.

Example (PDF):

function executer(n1, n2, fn) {

const res = fn(n1, n2);

[Link](res);

const add = (n1, n2) => n1 + n2;

executer(10, 20, add);

Here:

 executer → HOF

 add → callback function

 executer(10, 20, add)

 fn → add

 fn(10, 20) → 30

 res → 30

 [Link](res) → prints 30
🔹 WHY THIS EXISTS?

 Reusability

 Asynchronous programming

 Clean design

🚨 CCEE TRAP

❌ Callback = higher order function


❌ Arrow function must be callback

Truth:

 Callback ≠ HOF

 HOF uses callback

🧠 KEYWORD

Function using function = HOF

4️⃣ Hidden Parameters in Functions

🔹 Hidden Parameter #1 → this

WHAT IS this?

this refers to object that calls the function

Example (PDF):

var p = new Object();

[Link] = canVote;

[Link]();

Here:

 this → p

🚨 BIG CCEE TRAP

canVote();
✔ this → window (browser)

🧠 KEYWORD

Caller decides this

5️⃣ Hidden Parameter #2 → arguments

🔹 WHAT IS THIS?

arguments is an array-like object holding passed values.

Example (PDF):

function add() {

var sum = 0;

for(var i=0; i<[Link]; i++){

sum += arguments[i];

[Link](sum);

🚨 CCEE TRAP

❌ arguments is real array


❌ arguments works in arrow function

Truth:

 arguments ≠ real array

 arrow functions do NOT have arguments

🧠 KEYWORD

arguments = old JS, not arrow

6️⃣ Objects in JavaScript


🔹 WHAT IS OBJECT?

Collection of properties + methods

✔ Everything in JS is object
✔ Even functions are objects

🔹 WAYS TO CREATE OBJECT (PDF)

1. Using Object()

var c1 = new Object();

[Link] = "i10";

2. Constructor Function

function Car(model, company){

[Link] = model;

[Link] = company;

var c2 = new Car("Fabia", "Skoda");

3. Object Literal (MOST USED)

var c3 = {

model: "X5",

company: "BMW"

};

🚨 CCEE TRAPS

❌ Object literal is JSON


❌ Constructor function is class
❌ new keyword optional

🧠 KEYWORD
Literal = fastest + simplest

🔥 BLOCK 4 (CONTINUED) — AS PER SIR’S PDF FLOW

AGENDA (FROM YOUR PDF – EXACT ORDER)

1. Prototype Inheritance

2. Constructor Functions

3. Class (ES6)

4. Array

5. Spread Operator

6. Rest Operator

7. Window Object

8. DOM (intro + manipulation basics)

1️⃣ Prototype Inheritance (VERY IMPORTANT FOR CCEE)

🔹 WHAT IS THIS?

JavaScript uses prototype-based inheritance, not classical inheritance.

Meaning:

 Objects inherit from other objects

 Not copied → linked

🔹 CORE CONCEPTS (EXAM WORDING)

1. [[Prototype]]

 Internal hidden link

 Every object has it

 Points to another object

2. Prototype Chain

 JS searches property in:


1. Object itself

2. Its prototype

3. Prototype’s prototype

 Ends at null

3. Delegation (BIG WORD)

JS does delegation, not duplication

Child object does NOT copy methods


It delegates to prototype

🚨 CCEE TRAPS

❌ Prototype = class
❌ Prototype copies properties
❌ Prototype inheritance is removed by class

All false.

🧠 KEYWORD

Search → chain → null

2️⃣ Constructor Functions (OLD BUT ASKED)

From PDF:

function Person(name){

[Link] = name;

[Link] = function(){

[Link]([Link]);

Child:

function Employee(id, name, salary){

[Link](this, name);
[Link] = id;

[Link]([Link], [Link]);

🔹 WHY THIS MATTERS?

Before ES6:

 Classes didn’t exist

 Constructor + prototype used

🚨 CCEE TRAPS

❌ Constructor function = class


❌ Prototype chain automatic
❌ call() creates inheritance

Truth:

 call() sets data

 prototype sets inheritance

🧠 KEYWORD

call = data
prototype = behavior

3️⃣ Class (ES6) — VERY COMMON MCQ

🔹 WHAT IS CLASS?

class is syntactic sugar over prototype inheritance

Meaning:

 Internally → still prototype

 Externally → looks OOP

🔹 KEY FEATURES (EXAM)


1. constructor()

 Called with new

 Initializes object

2. extends

 Used for inheritance

3. super()

 Calls parent constructor

4. static methods

 Belong to class

 NOT to object

5. Private fields (#)

 Introduced later

 Accessible only inside class

🚨 CCEE TRAPS

❌ Class removes prototype


❌ Static method accessible via object
❌ super() optional in child constructor

🧠 KEYWORD

class = syntax only

4️⃣ Array (EASY BUT TRAPPY)

🔹 WHAT IS ARRAY?

Special variable holding multiple values

🔹 CREATION (PDF)

✔ Preferred:

let fruits = ["apple", "banana"];


❌ Old:

let fruits = new Array("apple");

🔹 IMPORTANT RULE

 Index starts from 0

 Can hold mixed types

🚨 CCEE TRAPS

❌ Array index starts from 1


❌ Array holds only same type

🧠 KEYWORD

Array = ordered + zero-based

5️⃣ Spread Operator ... (VERY IMPORTANT)

🔹 WHAT IS THIS?

Spread operator expands elements

🔹 USE CASES (PDF)

With Arrays

const copy = [...arr];

Merge Arrays

const all = [...a, ...b];

With Objects

const p = {...person, age:31};

Later properties overwrite earlier ones

🚨 CCEE TRAPS
❌ Spread modifies original
❌ Spread deep copies object

Truth:

 Spread = shallow copy

🧠 KEYWORD

Spread = unpack

6️⃣ Rest Operator ...

🔹 WHAT IS THIS?

Collects multiple values into one


🔹 RULE (VERY IMPORTANT)

Rest must be LAST parameter

Example:

function sum(...nums){}

🔹 Rest in Destructuring

const [a, ...rest] = arr;

🚨 CCEE TRAPS

❌ Rest and spread same


❌ Rest can be in middle

🧠 KEYWORD

Spread opens, Rest collects

7️⃣ Window Object

🔹 WHAT IS THIS?

window is browser’s global object

 Created automatically

 Global variables attach to it

🚨 CCEE TRAPS

❌ window is JS object
❌ window exists in [Link]

🧠 KEYWORD

Browser = window

8️⃣ DOM (Document Object Model)


🔹 WHAT IS DOM?

Browser creates tree representation of HTML

Structure:

window → document → html → body → elements

🔹 SELECTION METHODS (PDF)

Method Returns

getElementById single element

getElementsByClassName HTMLCollection

getElementsByTagName HTMLCollection

querySelector first match

querySelectorAll NodeList

🚨 CCEE TRAPS

❌ querySelectorAll returns element


❌ innerText = innerHTML

🧠 KEYWORD

querySelector = CSS selector

✅ JAVASCRIPT — REMAINING PARTS (FINAL, SIMPLE)

1️⃣ OPERATORS (VERY BASIC BUT ASKED)

Arithmetic

+ - * / %

Comparison (IMPORTANT)

== // value check (type conversion)


=== // value + type check (STRICT)

Example:

5 == "5" // true

5 === "5" // false

👉 Remember this line only:

=== is safer than ==

Logical

&& // AND

|| // OR

! // NOT

2️⃣ CONTROL STRUCTURES

if–else

if(age > 18){

vote();

}else{

noVote();

switch

switch(day){

case 1: break;

default: break;

Loops

for

while

do-while
👉 Exam point:
JS control structures work same like C/Java.

3️⃣ STRINGS & STRING METHODS (EASY MARKS)

let s = "CDAC Pune";

Common methods:

[Link]

[Link]()

[Link]()

[Link](0,4)

[Link](" ")

Example:

"abc,def".split(",") // ["abc","def"]

4️⃣ NUMBERS & NUMBER METHODS

let x = 10.567;

Methods:

parseInt("10.5") // 10

parseFloat("10.5") // 10.5

[Link](2) // "10.57"

⚠️Trap:

parseInt("10abc") // 10

5️⃣ BOOLEAN VALUES

Only two:

true

false

Falsy values (important):


false, 0, "", null, undefined, NaN

6️⃣ DATE & DATE METHODS (SMALL BUT TRAPPY)

let d = new Date();

Methods:

[Link]() // day

[Link]() // 0–11 ⚠️

[Link]()

👉 Trap to remember:

Month starts from 0, not 1

7️⃣ ARRAYS & ARRAY METHODS

let arr = [10,20,30];

Methods:

[Link](40)

[Link]()

[Link]

[Link]()

[Link]()

👉 Array index starts from 0

8️⃣ FUNCTIONS (LEFTOVER CONCEPTS)

Function Closure (IMPORTANT)

function outer(){

let x = 10;

return function inner(){

return x;

}
}

Meaning:

Inner function remembers outer variable

One-line memory:

Function + memory = closure

9️⃣ OOP CONCEPTS IN JS (THEORY ONLY)

Encapsulation

 Data inside object

 Access via methods

Abstraction

 Hide internal details

 Show only required

Polymorphism

 Same function name

 Different behavior

👉 No deep coding needed for CCEE

🔟 DOM EVENTS (VERY IMPORTANT)

[Link] = function(){}

[Link]("click", fn)

👉 Preferred:

addEventListener

1️⃣1️⃣ FORMS & FORM VALIDATION

<form onsubmit="return validate()">

function validate(){
if(name==""){

return false;

👉 Validation happens before form submission

1️⃣2️⃣ REGULAR EXPRESSIONS (BASIC ONLY)

let re = /abc/;

Used for:

 email

 phone

 pattern check

👉 CDAC asks definition only

1️⃣3️⃣ ERRORS & DEBUGGING

try{

// code

}catch(e){

[Link](e);

Debugging:

[Link]()

1️⃣4️⃣ BROWSER DEV TOOLS

 Console

 Elements

 Network

👉 Used for debugging JS in browser


1️⃣5️⃣ JSLint (THEORY ONLY)

Tool to check code quality & errors

No coding questions.

✅ FINAL PART: jQuery, AJAX, JSON, Promise (CCEE-FOCUSED)

1️⃣ jQuery (IMPORTANT BUT SIMPLE)

WHAT IS jQuery?

jQuery is a JavaScript library that makes DOM, events, and AJAX easier.

Hinglish:

JS ka shortcut version samajh lo.

WHY jQuery EXISTS?

Before jQuery:

 Too much JS code

 Browser compatibility issues

jQuery:

 Less code

 Same output

 Works in all browsers

HOW TO ADD jQuery

<script src="[Link]"></script>

BASIC SYNTAX (VERY IMPORTANT)

$(selector).action();

Examples:
$("p").hide(); // all <p>

$("#id").hide(); // id

$(".class").hide(); // class

$(this).hide(); // current element

🧠 Memory:

$ = jQuery

jQuery FEATURES (MCQ)

 DOM manipulation

 CSS manipulation

 Events

 Effects / animation

 AJAX

🚨 CCEE TRAPS (jQuery)

❌ jQuery replaces JavaScript


❌ $ is a keyword
❌ jQuery is server-side

✔ Truth:

 jQuery = JS library

 Runs in browser

2️⃣ AJAX (VERY COMMON MCQ)

WHAT IS AJAX?

Asynchronous JavaScript and XML

Meaning:

Load/send data without reloading page

AJAX FLOW (REMEMBER THIS ORDER)


1. User action

2. JS sends request

3. Server responds

4. Page updates (no reload)

WHY AJAX?

 Faster UI

 Better user experience

AJAX CAN USE:

 XMLHttpRequest (XHR)

 fetch()

 jQuery AJAX

3️⃣ JSON (VERY IMPORTANT)

WHAT IS JSON?

Lightweight data format for data exchange

Looks like JS object but not JS object.

Example:

"name": "John",

"age": 30

JSON RULES (EXAM)

 Keys in double quotes

 No functions

 Data only
JSON ↔ JS

[Link](obj) // JS → JSON

[Link](str) // JSON → JS

🧠 Memory:

stringify = send
parse = receive

4️⃣ XMLHttpRequest (XHR)

Old AJAX way.

Steps:

var xhr = new XMLHttpRequest();

[Link]("GET", url, true);

[Link]();

🚨 CCEE TRAP

❌ XHR reloads page


❌ XHR is synchronous by default

✔ Default = asynchronous

5️⃣ Promise (VERY IMPORTANT THEORY)

WHAT IS PROMISE?

Promise represents future result of async operation.

PROMISE STATES

1. Pending

2. Fulfilled

3. Rejected

Once fulfilled/rejected → settled forever


WHY PROMISE?

To avoid:

Callback hell

HANDLING PROMISE

.then()

.catch()

6️⃣ async / await (MODERN, THEORY ONLY)

 Built on Promise

 Makes async code look synchronous

async function f(){

let data = await fetch(url);

🧠 Memory:

await waits, async allows await

7️⃣ Fetch API (MODERN AJAX)

WHAT IS FETCH?

Modern alternative to XHR

Features:

 Uses Promises

 Cleaner syntax

 No open() / send()

BASIC FETCH

fetch(url)
.then(res => [Link]())

.then(data => [Link](data))

.catch(err => [Link](err));

🚨 CCEE TRAPS

❌ fetch is synchronous
❌ fetch doesn’t use promises

✔ fetch returns Promise

8️⃣ jQuery vs AJAX vs Fetch (1 MCQ TYPE)

Feature jQuery AJAX Fetch

Based on jQuery Promise

Modern ❌ ✅

Syntax Short Clean

✅ FINAL STATUS (VERY CLEAR)

✔ JavaScript Core → DONE

✔ DOM → DONE

✔ jQuery → DONE

✔ AJAX / JSON → DONE

✔ Promise / Fetch → DONE

🎯 Your Web Programming JS side is 100% COMPLETE for CCEE

No missing syllabus.
No hidden topic left.

🧠 10 GOLDEN LINES (READ ONCE BEFORE EXAM)

1. jQuery is a JS library

2. $ means jQuery
3. AJAX = no page reload

4. JSON = data format, not JS

5. stringify = send

6. parse = receive

7. Promise has 3 states

8. fetch returns Promise

9. async + await simplify async

10. XHR is old AJAX

What you want Syntax

By id $("#id")

By class $(".class")

By tag $("tag")

Tag + class $("[Link]")

Tag + id $("tag#id")

🔥 [Link] — TAUGHT DIRECTLY FROM YOUR PDF (CCEE MODE)

1️⃣ What is [Link] (FROM PDF)

WHAT IS IT?

[Link] is a JavaScript runtime built on Google’s V8 engine.

Simple words:

Browser ke bahar JavaScript chalane ka tool.

KEY POINTS (FROM PDF)

 Developed by Ryan Dahl (2009)


 Built on Google V8 JavaScript Engine

 Runs outside the browser

 Used to build scalable network applications

 Uses non-blocking I/O

CCEE TRAP 🚨

❌ [Link] is a programming language


❌ [Link] is a framework

✔ Correct: [Link] is a runtime environment

REMEMBER LINE 🧠

[Link] = JavaScript runtime (not language)

2️⃣ Browser JavaScript vs [Link] (VERY IMPORTANT)

Browser JS [Link]

Runs in browser Runs on server

Has DOM ❌ No DOM

Has window ❌ No window

Used for UI Used for backend

CCEE TRAP 🚨

❌ DOM available in [Link]

✔ DOM is browser-only

REMEMBER LINE 🧠

Browser = UI, Node = Server

3️⃣ JavaScript is Single-Threaded (FROM PDF)


WHAT DOES SINGLE-THREADED MEAN?

JavaScript has only one call stack


Executes one task at a time

PROBLEM?

Long tasks (file read, DB, network) would freeze the app

SOLUTION?

👉 Asynchronous programming + Event Loop

CCEE TRAP 🚨

❌ Single-threaded means slow

✔ Single-threaded + async = fast & non-blocking

REMEMBER LINE 🧠

One stack, many tasks via async

4️⃣ Asynchronous Programming in JS (FROM PDF)

WHAT IS ASYNC?

Long-running tasks are handled without blocking main thread

Examples:

 File read

 Network request

 Timer

IMPORTANT LINE (PDF LOGIC)

Tasks are handled concurrently, not simultaneously


CCEE TRAP 🚨

❌ Async = multi-threaded

✔ Async ≠ multi-threaded

5️⃣ EVENT LOOP (MOST IMPORTANT 🔥🔥🔥)

This is the HEART of [Link] MCQs.

Components (FROM PDF)

1. Call Stack

 Executes synchronous JS

 Follows LIFO

2. Background APIs (Web APIs / libuv)

 Handles:

o Timers

o File system

o Network

3. Callback Queue (Macrotask Queue)

 setTimeout

 I/O callbacks

4. Microtask Queue

 Promises

 then(), catch()

5. Event Loop

 Connects everything
 Pushes tasks to call stack

MOST IMPORTANT RULE 🚨

Microtask Queue is executed BEFORE Callback Queue

PDF EXAMPLE OUTPUT

[Link]("Start");

setTimeout(() => {

[Link]("From Macrotask");

}, 0);

[Link]().then(() => {

[Link]("From Microtask");

});

[Link]("End");

OUTPUT:

Start

End

From Microtask

From Macrotask

CCEE TRAP 🚨

❌ setTimeout(0) runs first

✔ Promise runs first

REMEMBER LINE 🧠
Promise first, timer later

6️⃣ libuv (FROM PDF – THEORY ONLY)

WHAT IS libuv?

 C/C++ library

 Powers [Link] async I/O

 Manages:

o Event loop

o File system

o Timers

o Network

CCEE LEVEL

👉 1 MCQ max

REMEMBER LINE 🧠

libuv = async engine of Node

7️⃣ Use Cases of [Link] (FROM PDF)

WHERE TO USE

 I/O bound apps

 Data streaming

 IoT

 JSON API

 Single Page Apps

WHERE NOT TO USE

 CPU-intensive tasks
 Heavy computation

CCEE TRAP 🚨

❌ Node best for CPU-heavy apps

✔ Node best for I/O-heavy apps

8️⃣ [Link] Installation & REPL (LOW PRIORITY)

 node --version

 node [Link]

 REPL = interactive shell

👉 MCQ only, no commands asked deeply

9️⃣ Modules (FROM PDF)

WHAT IS A MODULE?

Reusable block of code

TYPES:

1. Built-in (fs, http, os)

2. User-defined

KEYWORDS:

 require()

 [Link]

REMEMBER LINE 🧠

require imports, exports shares

🔟 REST & HTTP Module (BASIC THEORY)

REST
 Uses HTTP

 Methods:

o GET → fetch

o POST → submit

o PUT → update

o DELETE → remove

HTTP Module

 Creates server

 req → request

 res → response

👉 Code not asked

🧠 FINAL NODE MEMORY (READ ONCE)

1. [Link] = JS runtime (V8)

2. Runs outside browser

3. No DOM, no window

4. JS single-threaded

5. Async via Event Loop

6. Promise > setTimeout

7. libuv handles async

8. Best for I/O, not CPU

9. require / exports

10. GET fetch, POST submit

🔥 [Link] – HTTP ROUTES, EXPRESS, MYSQL

(Exactly from your PDF, only exam-relevant)


1️⃣ HTTP SERVER ROUTING ([Link] core)

WHAT IS ROUTING?

Routing means deciding how server responds to a request based on:

 URL (path)

 HTTP method (GET / POST / etc.)

Example:

 GET / → Home page

 GET /about → About page

HOW ROUTING IS DONE IN HTTP MODULE (PDF CODE IDEA)

if ([Link] == "/" && [Link] == "GET") {

// home

} else if ([Link] == "/about") {

// about

} else {

// 404

PROBLEM WITH THIS APPROACH

 Too much manual code

 Hard to manage when routes increase

 You must handle:

o headers

o status codes

o routing logic yourself

👉 This is WHY Express exists

🧠 REMEMBER

HTTP module = low level, manual routing


2️⃣ nodemon

WHAT IS nodemon?

A developer tool that automatically restarts Node app when files change.

WHY nodemon?

Without nodemon:

 Stop server

 Restart server

 Again & again ❌

With nodemon:

 Auto restart ✅

IMPORTANT POINT (CCEE)

 nodemon is NOT part of [Link]

 It is a development tool

🧠 Memory:

nodemon = auto restart

3️⃣ EXPRESS (VERY IMPORTANT)

WHAT IS EXPRESS?

Express is a fast, minimal web framework for [Link]

Simple words:

Node ke upar ek shortcut framework

WHY EXPRESS EXISTS?

Because:

 http module is too low-level

 Routing becomes messy


 JSON parsing is manual

Express gives:

 Easy routing

 Middleware

 Cleaner code

🧠 REMEMBER

Express runs on top of [Link]

4️⃣ EXPRESS vs HTTP SERVER (VERY SCORING)

HTTP SERVER

 Built-in Node module

 Manual routing

 Manual headers

 More code

EXPRESS

 Framework

 Easy routing

 Middleware support

 Less code, cleaner

🧠 ONE-LINE MEMORY:

http = raw, express = refined

5️⃣ ROUTING IN EXPRESS (IMPORTANT)

EXPRESS ROUTE STRUCTURE

[Link](PATH, HANDLER)

Where:

 app → express instance


 METHOD → get / post

 PATH → URL

 HANDLER → function

EXAMPLE (FROM PDF)

[Link]("/", (req, res) => {

[Link]("Home Page");

});

[Link]("/about", (req, res) => {

[Link]("About Page");

});

[Link]("/login", (req, res) => {

[Link]("Login data received");

});

IMPORTANT RULE (CCEE)

Route runs only when PATH + METHOD both match

🧠 REMEMBER

Express listens for URL + HTTP method

6️⃣ req and res (EXPRESS BASICS)

req (request)

 Data sent by client

 URL, method, body, params

res (response)
 Used to send data back

 HTML, JSON, text

🧠 Memory:

req = from client, res = to client

7️⃣ MYSQL WITH [Link] (BASIC THEORY ONLY)

⚠️CCEE does NOT expect deep DB coding.

HOW NODE CONNECTS TO MYSQL (PDF IDEA)

 Install mysql module

 Create connection or pool

 Execute query

WHAT IS createPool()?

Pool manages multiple DB connections

Why?

 Better performance

 Avoid opening/closing connection every time

IMPORTANT POINT (CCEE)

 MySQL queries in [Link] are asynchronous

🧠 Memory:

DB calls do not block Node

8️⃣ VERY IMPORTANT YES / NO FACTS (EXAM GOLD)

 Express is a framework ✅

 Express replaces Node ❌

 nodemon is for production ❌


 HTTP module is built-in ✅

 Express simplifies routing ✅

 MySQL queries are async ✅

🧠 FINAL NODE + EXPRESS + MYSQL MEMORY (READ ONCE)

 Routing = URL + method

 nodemon = auto restart

 Express runs on Node

 http is built-in

 Express simplifies routing

 [Link] / [Link]

 req from client, res to client

 mysql2 used for DB

 createPool manages connections

 DB calls are async

EXPRESS ROUTER, MIDDLEWARE, BCRYPT, JWT

(CCEE-focused, simple, PDF-based)

1️⃣ [Link] (VERY LIKELY 1 MCQ)

WHAT IS [Link]?

[Link]() is a mini Express app used only for routing.

Simple words:

Routes ko alag file me todne ka tareeka.

WHY [Link] EXISTS?

Without Router:

 All routes in [Link]


 File becomes huge

 Hard to maintain

With Router:

 /users → [Link]

 /products → [Link]

HOW IT WORKS (LOGIC ONLY)

 Create router

 Define routes on router

 Export router

 Mount router using [Link]()

VERY IMPORTANT LINE (CCEE)

Router helps in modular and maintainable routing

🚨 CCEE TRAPS

❌ Router replaces Express


❌ Router is database related

✔ Router is part of Express

🧠 REMEMBER

Router = routes in separate files

2️⃣ Middleware (HIGH IMPORTANCE)

WHAT IS MIDDLEWARE?

A function that runs between request and response.

Flow:

Request → Middleware → Response


WHAT CAN MIDDLEWARE DO?

 Modify request

 Modify response

 Stop request

 Pass request forward

next() (VERY IMPORTANT)

next() passes control to the next middleware

❌ No next() → request stuck

COMMON USES (PDF)

 Logging

 CORS

 JSON parsing

 Authentication / Authorization

🚨 CCEE TRAPS

❌ Middleware runs after response


❌ Middleware cannot modify request

✔ Middleware runs before response

🧠 REMEMBER

Middleware = gatekeeper

3️⃣ Password Hashing (SECURITY THEORY)

GOLDEN RULE (EXAM)

❌ Never store passwords in plain text


WHY HASHING?

 Protect passwords

 Prevent data leaks

 Stop rainbow-table attacks

4️⃣ crypto-js (JUST FOR COMPARISON)

WHAT IS crypto-js?

 General cryptography library

 Supports SHA256, MD5, AES

IMPORTANT (PDF LINE)

❌ Not recommended for password hashing

Why?

 Too fast

 Not resistant to brute force

🧠 REMEMBER

crypto-js = general purpose, not password safe

5️⃣ bcrypt (VERY IMPORTANT)

WHAT IS bcrypt?

A password hashing library specially designed for security.

WHY bcrypt IS BETTER?

From PDF:

 Automatic salt generation

 Slow by design (good for security)

 Adaptive cost factor


 Protects against rainbow-table attacks

bcrypt KEYWORDS (CCEE)

 hash() → create hash

 compare() → check password

 Salt → random value added

 Cost factor → hashing strength

🚨 CCEE TRAPS

❌ bcrypt encrypts password


❌ bcrypt stores original password

✔ bcrypt hashes, not encrypts

🧠 REMEMBER

bcrypt = slow, salted, secure

6️⃣ JWT (JSON Web Token) — THEORY ONLY

WHAT IS JWT?

A token-based authentication mechanism

Used for:

 Login

 Authorization

 Stateless authentication

HOW JWT WORKS (VERY SIMPLE)

1. User logs in

2. Server creates token

3. Client stores token


4. Token sent with every request

WHY JWT?

 No session storage

 Scalable

 Stateless

🚨 CCEE TRAPS

❌ JWT stores password


❌ JWT is encryption

✔ JWT is signed token

🧠 REMEMBER

JWT = token, not session

You might also like