MODULE–III : JAVASCRIPT COMPLETE DETAILED NOTES
WITH ALL TOPICS & EXAMPLES
1. Introduction to JavaScript
JavaScript is a high-level scripting language used for frontend web development.
It makes websites interactive and dynamic.
JavaScript is mainly used for:
• Form validation
• Popup messages
• Dynamic content
• Games
• Calculator
• Animation
• Event handling
JavaScript works together with:
• HTML → Structure
• CSS → Design
• JavaScript → Functionality
Example:
<script>
alert("Welcome to JavaScript");
</script>
2. JavaScript Basics
JavaScript code can be written in two ways:
1. Internal JavaScript
2. External JavaScript
Internal JavaScript Example:
<script>
[Link]("Hello");
</script>
External JavaScript
External JavaScript is written in separate .js file.
Example:
<script src="[Link]"></script>
3. Keywords
Keywords are reserved words having special meaning in JavaScript.
Common Keywords:
• var
• let
• const
• if
• else
• switch
• while
• for
• break
• continue
• function
• return
Example:
let age = 20;
4. Identifiers
Identifiers are names given to variables, functions, arrays, and objects.
Rules of Identifiers:
• Cannot start with number
• Spaces are not allowed
• Special symbols not allowed except _ and $
• JavaScript is case-sensitive
Correct Identifiers:
• studentName
• age
• marks1
Wrong Identifiers:
• 1name
• my name
let studentName = "Rahul";
5. Datatypes
Datatype tells the type of value stored inside variable.
Main Datatypes:
1. Number
Example:
let x = 10;
String Datatype
String stores text values.
Example:
let name = "Rahul";
Boolean Datatype
Boolean stores true or false values.
Example:
let isPass = true;
Undefined Datatype
Undefined means value is not assigned.
Example:
let a;
Null Datatype
Null means empty value.
Example:
let b = null;
Object Datatype
Object stores data in key-value pair.
Example:
let student = {
name: "Ram",
age: 20
};
6. Variables and Constants
Variables are containers used to store data.
JavaScript provides:
• var
• let
• const
let:
• Modern way
• Value can change
const:
• Constant value
• Cannot be changed
var:
• Old method
• Function scope
let age = 20;
const pi = 3.14;
var city = "Delhi";
Difference between var, let and const
Main differences are:
• var allows redeclaration
• let does not allow redeclaration
• const cannot be reassigned
var x = 10;
let y = 20;
const z = 30;
7. Operators
Operators are symbols used to perform operations.
Types of Operators:
1. Arithmetic
2. Comparison
3. Logical
4. Assignment
let a = 10;
let b = 5;
[Link](a+b);
[Link](a-b);
Arithmetic Operators
Arithmetic operators perform mathematical operations.
Operators:
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
let x = 10;
let y = 3;
[Link](x % y);
Comparison Operators
Comparison operators compare two values.
Operators:
==
===
!=
>
<
>=
<=
[Link](5=="5");
[Link](5==="5");
Logical Operators
Logical operators combine conditions.
Operators:
&& AND
|| OR
! NOT
let age = 20;
if(age > 18 && age < 60){
[Link]("Valid");
}
Assignment Operators
Assignment operators assign values.
Examples:
=
+=
-=
*=
/=
let x = 5;
x += 2;
8. Decision Making Statements
Decision making statements are used to execute code based on conditions.
Types:
• if
• if-else
• nested if
• else-if ladder
• switch
let age = 18;
if(age >= 18){
[Link]("Adult");
}
if-else Statement
if-else is used when there are two conditions.
Example:
let age = 15;
if(age >= 18){
[Link]("Adult");
}
else{
[Link]("Minor");
}
Nested if Statement
Nested if means if statement inside another if statement.
Example:
let age = 20;
let citizen = true;
if(age >= 18){
if(citizen){
[Link]("Eligible");
}
}
Else-if Ladder
Else-if ladder is used for multiple conditions.
Example:
let marks = 75;
if(marks >= 90){
[Link]("A");
}
else if(marks >= 70){
[Link]("B");
}
else{
[Link]("C");
}
Switch Case
Switch is alternative of multiple else-if statements.
Example:
let day = 2;
switch(day){
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
default:
[Link]("Invalid");
}
9. Iteration Statements or Loops
Loops repeat code multiple times.
Types:
• for loop
• while loop
• do-while loop
• for...of loop
• for...in loop
for(let i=1; i<=5; i++){
[Link](i);
}
for Loop
for loop is used when number of repetitions is known.
Syntax:
for(initialization; condition; increment/decrement)
for(let i=1; i<=5; i++){
[Link](i);
}
while Loop
while loop checks condition before execution.
Example:
let i = 1;
while(i <= 5){
[Link](i);
i++;
}
do-while Loop
do-while loop executes at least one time.
Example:
let i = 1;
do{
[Link](i);
i++;
}
while(i<=5);
Difference between while and do-while
while loop:
• Condition checked first
• May not execute
do-while loop:
• Executes at least once
• Condition checked later
let i = 1;
for...of Loop
for...of loop is used for arrays and strings.
Example:
let arr = [10,20,30];
for(let value of arr){
[Link](value);
}
for...in Loop
for...in loop is used for object properties.
Example:
let student = {
name:"Ram",
age:20
};
for(let key in student){
[Link](key);
}
10. Jump Statements
Jump statements control loop execution.
Types:
• break
• continue
for(let i=1; i<=5; i++){
[Link](i);
}
break Statement
break statement stops loop immediately.
Example:
for(let i=1; i<=5; i++){
if(i==3){
break;
}
[Link](i);
}
continue Statement
continue skips current iteration.
Example:
for(let i=1; i<=5; i++){
if(i==3){
continue;
}
[Link](i);
}
11. Comments in JavaScript
Comments are used to explain code.
Types:
1. Single-line comment
2. Multi-line comment
// Single-line comment
/*
Multi-line
comment
*/
12. Input and Output in JavaScript
JavaScript provides methods for input and output.
Output Methods:
• [Link]()
• alert()
• [Link]()
Input Method:
• prompt()
let name = prompt("Enter your name");
alert(name);
13. Important Interview and Exam Questions
Difference between == and ===
==
• Checks value only
===
• Checks value and datatype
5 == "5" // true
5 === "5" // false
Difference between let and const
let:
• Value can change
const:
• Value cannot change
let age = 20;
const pi = 3.14;
Features of JavaScript
Main Features:
• Lightweight
• Fast
• Interpreted language
• Platform independent
• Dynamic typing
• Object-oriented
[Link]("JavaScript Features");
Real Life Example
Login Example using if-else statement:
let password = "1234";
if(password == "1234"){
[Link]("Login Success");
}
else{
[Link]("Wrong Password");
}
Summary
Module–III explains complete basics of JavaScript including:
• Variables
• Datatypes
• Operators
• Conditions
• Loops
• Switch case
• Break and continue
• Input and output
• Important interview questions
These concepts are the foundation of frontend web development and JavaScript programming.
[Link]("Module Completed");