javascript


console.log("ved varshney");
fullName="dhruv";
age=22;
price=99.99;
x=null;
y=undefined;
isfollow=true;
fullName=45;
console.log(fullName);

data types primitives

let age = 22;
console.log(age);
let name="ved";
console.log(name);
let price=100.78;
console.log(price);
let isfollow=true;
console.log(isfollow);
let u=undefined;
console.log(u);
let n=null;
console.log(n);
let x=BigInt("123");
console.log(x);
let y=Symbol("hello!");
console.log(y);

non primitive

const student={
fullName : "ved",
age:22,
cgpa:8.87,
ispass:true
};
console.log(student);
console.log(student["age"]);
console.log(student.age);
student.age+=1;
console.log(student.age);
console.log(typeof student.age);

operator and conditional statement

power operator
let a=5,b=2;
console.log(a**b); // 25
ternary operator
let age=16;
age>=18? console.log("valid"):console.log("not valid");

take input from user

let a=prompt("enter no.=")
console.log(a);

loops for-of
let str="ved varshney";
for(let a of str){
    console.log(a);
}

loops for-in
let Student={
name:"ved",
age:22,
cgpa:8.87,
section:2,
};
for(let a in Student){
    console.log(Student[a]);
}

String

let str="ved varshney";
console.log(str);
console.log(str[0]);

template string

let s=`hello madam ji`;
console.log(s);

let employee={
name : "ram",
age:30,
salary:20,
};

string interpolation
let str=`salary of ram is ${employee.salary} and age of ram is ${employee.age}`;
console.log(str);

string methods

let str="hellololo";
console.log(str.toLowerCase());
console.log(str.toUpperCase());
let s="    hey hello   ";
console.log(s.trim());

console.log(str.slice(1,4));
if there is no parameter in slice - print full string
console.log(str.slice());

console.log(str.concat("ved"));
console.log(str.replace("lo","h"));
console.log(str.replaceAll("lo","p"));
let s = prompt("enter name=");
console.log("@"+s+s.length);

let marks=[89,45,88,56,32,75,96];
console.log(marks);
let sum=0;
for(let i=0; i<marks.length; i++){
sum+=marks[i];
}
console.log(sum/marks.length);

let arr=[250,645,300,900,50];
for(let i=0; i<arr.length; i++){
    let off=arr[i]-arr[i]/10;
    arr[i]=off;
}
console.log(arr);

//if we want to access index element out of array size then - it show undefined
let arr=[1,2,3];
console.log(arr[3]); // undefined

// method of array

let arr=[12,34,56,78,45,65,73];
console.log(arr);
arr.push(99,100); // add at end (single or multiple we can add)
console.log(arr);

let val=arr.pop(); // delete from end
console.log(val);
console.log(arr);

console.log(arr.toString());

let brr=[5,12,45,33,67];
let crr=[11];
console.log(arr.concat(brr,crr)); // also add multiple array

arr.unshift(11); //add in start
console.log(arr);
 
let a = arr.shift(); // delete from start and return
console.log(a);
console.log(arr);

console.log(arr.slice(1,3)); // as it is substring
console.log(arr.slice());  // give full array

// splice method

arr.splice(2,1,560); // replace
console.log(arr);

arr.splice(2,2);  // delete
console.log(arr);

arr.splice(3,0,101,102);  // insert
console.log(arr);

arr.splice(2); //if we give only 1 parameter , splice delete all elements from given index
console.log(arr);






                                               




                                        
                                

                               


Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.