Skip to main content

Posts

Showing posts with the label javascript

strings in javascript

 here in this blog we are going to learn about the strings in the javascript replit link(fb login) here are the following examples. let name ="anwar" // console.log(name) // console.log(name.length) // console.log(typeof name) // console.log(name[1]) // // template literals in StringList // let name1= "sabih" // let name2="anwar" // let sentence=`my name is ${name1} ${name2}` // console.log(sentence) // // escape sequence characters // name='anw\'ar' // console.log(name) // name='anw\nar' // console.log(name) // name='anw\tar' // console.log(name) // name='anw\rar' // console.log(name) // escape sequence character types // \b Backspace // \f Form Feed // \n New Line // \r Carriage Return // \t Horizontal Tabulator // \v Vertical Tabulator // console.log(name.toUpperCase()) // console.log(name.toLowerCase()) // console.log(name.slice(2)) // console.log(name.slice(2,4)) // console.log(name.replace("an...

function in javascript

 here in this blog we are going to study about function in javascript repel for functions(fb login) so here is the code as follows // function in javascript function oneplusavg(x,y) {   console.log("done")   return Math.round(1+(x+y)/2) } // modern function writing way // this is arrow function const hello = ()=>{   console.log("arey maza aa gaya bhai") } let a=1; let b=2; let c=3; hello(); console.log("one plus average of a and b is ", oneplusavg(a,b)) console.log("one plus average of b and c is ", oneplusavg(b,c)) console.log("one plus average of a and c is ", oneplusavg(a,c))

while and do while loop in javascript

 so in this blog we will learn about the while and do while loop of javascript replit link(login with fb) here are the codes as follows // while loop in javascript let n=prompt("enter the value of n") n=Number.parseInt(n) let i=0; // while (i<n){ //   console.log(i) //   i++; // } // do while loop in javascript do{   console.log(i)   i++; }while(i<n)

for loop, for in loop, for of loop in javascript

 here in this blog we are going to work with the  for loop for in loop  for of  loop link for replit(login from fb) so here are the following codes as follows //for loop in javascript for (let i=0;i<5;i++){console.log(i)} // program to add first natural numbers let sum=0 let n = prompt("enter the value of n") n= Number.parseInt(n) for(let i=0;i<n;i++)//here we are using let so the value is only valid inside the curly brackets only but when we work with var instead of let than it becomes global and outside also i value can be obtained {sum += (i+1)} console.log("the sum of "+ n + " natural numbers is" + sum ) //for in loop in javascript // let obj = { //   sabih:99, //   anwar:98, //   shayaan:100, //   ghufrana:23, //   rizwana:66 // } // for(let a in obj){console.log("marks of "+ a+" are "+obj[a])} // // for of loop in javascript it mainly works in arrays // for(let b of "shayaan"){console.log(b)}

if else statement in javascript and ternary operator

 here in this blog we are going to work with the if else and the ternary operator also link for this example link for example replit ka login facebook see karo let a =prompt("hey whats your age"); a= Number.parseInt(a); if (a<0){alert("this is an invalid age")} if (a<9){alert("you are a kid and dont even think of driving")} if (a<18 && a>=9){alert("you can think of driving after 18")} if (a>18){alert("you are eligible for driving")} //here we are working with the ternary operator which satisfies the condition at the same line console.log("you can",(a<18?"not drive":"drive"))

Primitive data types and objects for java script

 Here in this blog, we are going to discuss the primitive data types nn ss bb u and it stands for n - null ( let a = null;) n - number ( let b = 13463; ) s - string ( let c = "Anwar") s - symbol ( let d = Symbol(" A good symbol") b - boolean ( let e = true; ) b - BigInt ( let f =BigInt("567") u - undefined ( let g = undefined / let g) Object in javascript Here in javascript, the objects are the same as the dictionaries in python but we call them here objects.

var Vs let Vs const

  Here in this blog, we are going to study the difference between let, var, and const in Javascript First Case, var means variable Here in the var condition, we can change the value of var means the variable identifier anywhere in the coding For Ex:- var a =2 var a =3 then console.log(a) would give you the output as 3 means the changed value of var. Second Case let means let us assume Here in the let condition, we can update the value for the identifier let but we can't change it. For ex:- let a ="hello" let a ="Anwar" {let a ="Sabih" console.log(a)} console.log(a) So the output for that will be  Sabih Hello And the output for the let a ="Anwar" will show an error against it because let is the function for the block operable between this {} and outside that it can be assumed only once. But if like a variable you want to assume then you can assume by the coding of a = "Anwar" but it is stored as a variable. Third case const means con...