Thursday, January 29, 2026

Python 31

  • JavaScript Syntax and variables
  • JavaScript Operators
  • JavaScript Conditional statements
  • JavaScript Loops
  • JavaScript Functions
  • JavaScript Interactions with HTML

JavaScript Syntax and Variables

What is JavaScript Syntax?

Syntax means the rules of  writing JavaScript code so that the browser can understand it(Just loke English has grammar,JavaSript has syntax)

Basic JavaScript syntax Rules

1.Statements end with semicolon ;

Forex:- alert("Hello JavaScript");

2.JavaScript is case-sensitive 

let name="Ravi";

let Name="Kiran";  // both are different variables

3.Comments in JavaScript 

// This is a comment 

 /*multi liner comment */

4.Blocks use {}

  if(true){ console.log("Inside block"); }

What is a variable??

A variable is used to store data that can be used later(Variable=Container for data)

JavaScript provides 3 keywords:

How to Declare variables in JavaScript 

 1.var(old-avoid)   for ex:- var city="Hyd" --old style avoid

2.let(recommended) for ex:- let age =25; 

3.Const(Constant) for ex:- const country="India";

  • JavaScript Operators
Operator are symbols used to perform operations on values.

A.Arithmetic Operators
let a=10;
let b=5;
console.log(a+b); //15
console.log(a-b); //5
console.log(a/b); //2    
console.log(a%b);//0
B.Assigment Operators
let x=10;
x+=5; // x=x+5;
console.log(x); //15
C.Comparison Operator
console.log(10>5) //true
console.log(10<5)//false
console.log(10=="10") //true
console.log(10==="10");//false
==compares value
===compares value and type (recommended)
D.Logical Operator
let age=20;
console.log(age>18 && age <60);  //true  && and  ! NOT  || or

  • JavaScript Conditional statements
A.If statement
 let marks =80
if (marks>=35){
   alert("pass");

 }
B. if else 
  let marks=30;
 if (marks >=35) {
alert("pass");
}
else {
alert("Fail");

}

C.else if 
let mark = 85;
 if (marks >=90) {
 alert("Grade A");
 }else if (marks>=75){
  alert("Grade B"); 
} else{
 alert ("Grade C")    
}

D. Switch
let day =2;
Switch(val){
 case 1:
   alert("monday");
   break;
case 2:
  alert("Tuesday");
 break;
default:
 alert("Invalid day");
}

Loop

While 

  let i=1;
        while (i<=val1){
           alert('message'+i)
           i++;

For

 for (let i=1;i<=5;i++){
           alert('message:' +i);
        }
         

Do while Loop

  let i=1;
        do {
           alert('message:' +i);
           i++;
        } while (i<=5)


JavaScript Function 

A function is a block of code that performs a task and can be reused 

A .Simple function

 function greet() {

  alert('Hello');

}

greet();

B. Function with parameters

function add(a,b){

return a+b;

}

Console.log(add(10,5) //15

C. Arrow function(intro)

Const multiply =(a,b) => a*b;

console.log(multiply(4,5)); //20


--Thanks


No comments:

Post a Comment