[Go to site: main page, start]

0% found this document useful (0 votes)
2 views2 pages

JavaScript Lecture

This document provides an overview of fundamental JavaScript concepts including loops, conditional statements, and functions. It explains various types of loops (for, while, do...while), conditional statements (if, if-else, if-else if-else), and the use of functions with examples. The summary emphasizes the efficiency of loops, the control of logical flow through conditionals, and the benefits of functions for code organization and reusability.

Uploaded by

saqib razaq
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)
2 views2 pages

JavaScript Lecture

This document provides an overview of fundamental JavaScript concepts including loops, conditional statements, and functions. It explains various types of loops (for, while, do...while), conditional statements (if, if-else, if-else if-else), and the use of functions with examples. The summary emphasizes the efficiency of loops, the control of logical flow through conditionals, and the benefits of functions for code organization and reusability.

Uploaded by

saqib razaq
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

JavaScript Lecture Notes

Loops, Conditional Statements, and Functions

1. Introduction
JavaScript is a widely used programming language for creating dynamic and interactive web
pages. This lecture covers fundamental programming concepts including loops, conditional
statements, and functions with clear explanations and examples.

2. Loops in JavaScript
Loops are used to repeatedly execute a block of code while a specific condition remains
true.

2.1 For Loop


The for loop is used when the number of iterations is known in advance.

for (let i = 1; i <= 5; i++) {


[Link]("Number: " + i);
}

2.2 While Loop


The while loop continues execution as long as the condition is true.

let i = 1;
while (i <= 5) {
[Link]("Count: " + i);
i++;
}

2.3 Do While Loop


The do...while loop ensures the code runs at least once.

let i = 1;
do {
[Link]("Value: " + i);
i++;
} while (i <= 5);

3. Conditional Statements
Conditional statements allow programs to make decisions based on different conditions.

3.1 If Statement
let age = 18;
if (age >= 18) {
[Link]("You are eligible to vote");
}

3.2 If Else Statement


let number = 5;
if (number % 2 === 0) {
[Link]("Even number");
} else {
[Link]("Odd number");
}

3.3 If Else If Else Statement


let marks = 75;

if (marks >= 80) {


[Link]("Grade A");
} else if (marks >= 60) {
[Link]("Grade B");
} else if (marks >= 40) {
[Link]("Grade C");
} else {
[Link]("Fail");
}

4. Functions in JavaScript
Functions are reusable blocks of code designed to perform a specific task.

4.1 Greet Function Example


function greet(name) {
[Link]("Hello, " + name + "! Welcome to JavaScript.");
}

greet("Ali");
greet("Sara");

5. Summary
• Loops execute repetitive tasks efficiently.
• Conditional statements control logical flow.
• Functions improve code organization and reusability.

You might also like