JavaScript Tutorial

JavaScript Rest Operator 0

JavaScript Rest Operator

Program 1 <html> <head> <script> function marksheet(rno,name,…args) { console.log(rno + ” “+ name) let i,sum=0,p,n n=args.length for(i=0;i<args.length;i++) { sum=sum+args[i] } console.log(“Total Marks : “+sum) p=sum/n console.log(“Percentages : “+p) } marksheet(101,”vishal Sharma”,78,88,99,75) console.log(“————————————“) marksheet(102,”Anil Mishra”,76,78,89,85,89)...

JavaScript Spread Operator 0

JavaScript Spread Operator

Program 1 <html> <head> <script> var a=[10,20,30,40,50] var b=[100,200,300,400,500] // var c=a.concat(b) // console.log(c) var c=[ …a, …b] console.log(c) // var b=[…a] // //console.log(b) // a.push(600) // console.log(b) // function display( …args) //rest operator...

JavaScript Error Handling Part – 3 0

JavaScript Error Handling Part – 3

Program 1 <html> <head> <script> function devide() { try { let str=prompt(“Enter a String”) alert(str) let i=parseInt(prompt(“Enter an index number for dispaly character”)) let n=str.length; if(i>=0 && i<n) alert(str.charAt(i)) else throw new Error(“Index out...

JavaScript Error Handling Part – 2 0

JavaScript Error Handling Part – 2

Program 1 <html> <head> <script> try { // hello() let a=100,b=0 if(b==0) throw new Error(“Division Error”) c=a/b console.log(c) } catch(e) { // console.log(“Unable to devide by zero”) // console.log(e.name) console.log(e.message) // console.log(e.stack) } </script>...

JavaScript Error Handling Part – 1 0

JavaScript Error Handling Part – 1

Program 1 <html> <head> <script> try //find out error { console.log(“Line of try before error”) hello() //error console.log(“next line of try after error”) console.log(100+100) } catch(e) // to handel to error { console.log(e.name) console.log(e.message)...

Arrow Function in JavaScript 0

Arrow Function in JavaScript

Program 1 <html> <head> <script> let maxnumber=(a,b) =>{ if(a>b) alert(“First number is grater”) else alert(“Second number is grater”) } // let factorial=n=>{ // let f=1 // while(n!=0) // { // f=f*n // n– //...

JavaScript Class Inheritance 0

JavaScript Class Inheritance

Program 1 class Base { constructor() { console.log(“This is a constructor of base class”) } } class Derived extends Base { constructor() { super() console.log(“This is a constructor of Derived class”) } } class...

Modules in JavaScript Part – 2 0

Modules in JavaScript Part – 2

Program 1 let stname=”Manish Verma” let stCourse=”MTech Course” function showData(cityname) { console.log(“This is my ” + cityname) } class MyClass { constructor() { console.log(“This is a constructor of my class”) } power(n,p) { let...

JavaScript Array forEach() Method 0

JavaScript Array forEach() Method

Program 1 // For Each // function display(itemname,index) // { // console.log(index+”—“+itemname) // } // let cityname=[“Indore”,”Delhi”,”Bhopal”,”Mumbai”,”Raipur”] // cityname.forEach(display) // function display(items,index,arr) // { // arr[index]=items+10 // } // let values=[10,20,30,40,50] // values.forEach(display) //...

JavaScript Date Object 0

JavaScript Date Object

Program 1 <html> <head><title>Java Script date Demo</title> <script language=”javascript”> document.writeln(“<center>”) var d=new Date(); document.writeln(d.toDateString()) document.writeln(“<br>”) document.writeln(“<br>”) if(d.getMonth()==1) document.writeln(d.getDate() + “-Feb-“+d.getFullYear()); //document.writeln(d) document.writeln(“<br>”) // document.writeln(d.toDateString()) document.writeln(“<br>”) // document.writeln(d.getDate()); // document.writeln(d.getMonth()); // document.writeln(d.getFullYear()); // document.writeln(d.getHours()); //document.writeln(d);...