Posts

Showing posts from October, 2020

Prototype used in Node.js

 Component Name: prototype.js -------------------------------------------------------------------------------- //Prototype ka use function me value ad karne ke liye kiya jata hai function student (){ this . name = "Abhishek" ; this . age = 29 ; this . email = "abhishekpratapsingh@gmail.com" } student . prototype ={ address : "Banglore" , getAddress : function (){ return this . address ; } } var stu = new student (); console . log ( stu . address );

Acess Ecamascript constructor value

 Component Name: ecamaScript.js ------------------------------------------------------------------ class Users { constructor (){ this . name = "Abhishek Pratap Singh" ; this . age = 28 ; } getName (){ return this . name ; } getAge (){ return this . age ; } } var user = new Users (); console . log ( user . getName (), user . getAge ());

Know JavaScript File Name

 file name: main.js ---------------------------------------------- var name = "pradeep" ; var user =( a , b ) => { var c = a + b ; console . log ( c ); } user ( 5 , 5 ); module. exports . abc = name ; ------------------------------------------------ -------------------------------gObject.js //__dirname, directory name janne ke liye //__filename, filename janne ke liye //require, // dusre folder ki file ko access ke liye //console, //buffer, //module, //exports // const { abc } = require("./main"); // console.log(__dirname); // console.log(__filename); // var main =require('./main'); console . log ( abc . main );

Anonymous Function In JavaScript

 file name: main.js ---------------------------------------------------------------------- var laptop = function (){ console . log ( "This is anonymous function " ); } laptop ();

Rest Parameters in ES6 JavaScript

  // Rest Parameters in ES6 JavaScript // old style // this is the problem when we have two many parameters // function sum(a,b,c,d,e,f) // { // console.log(a+b+c+d+e+f); // } // sum(1,2,3,4,5,6); // ES6 style // rest parameter as a array kaunt karke deta hai function sum (... inputs ) { console . log (... inputs ) let total = 0 ; for ( let i of inputs ){ total += i ; } console . log ( total ); } sum ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 );

es6 Default Parameters in Javascript

// es6 Defaul Parameters in Javascript const multi = ( a , b = 5 ) => { console . log ( `the muliplication of two no is ${ a * b }` ); } multi ( 4 );

Fat Arrow Function in JavaScript

  // Fat Arrow Function in JavaScript // Old style es5 function // var sum = function() // { // var a = 5; // var b = 10; // return a+b; // } // console.log(sum()); // es6 Latest Fat Arrow Function // const sum = () =>{ // let a = 65; // let b = 10; // return a+b; // } // console.log(sum()); // es6 latest another style let a = 20 ; let b = 50 ; const sum = () => a + b console . log ( sum ());

Object Destructuring in JavaScript

  // Object Destructuring in JavaScript // old style // const bioData = // { // name: "abhishek", // age: 28, // deg: "Mca", // hob: { // first: "palying", // sec: "Programming" // } // } // console.log(`My name is ${bioData.name} `) // New Style // let {name:Myname,deg,age, hob} = bioData; // console.log(`My name is ${Myname}. My age is ${age}. my qualification is ${deg}. // i love ${hob.sec}`); // 2020 style const ReactNativeKing = { Laptop : "Macbook Air" , Programming : "JavaScript" , FrameWork : "ReactNative" , secFrameWork : "ReactJs" , Dream : { Place : "switzerland" , Car : "RangeRover" , Person : "Elon Musk" } } let { Laptop , Programming , FrameWork , secFrameWork , Dream } = ReactNativeKing ; console . log ( `My Laptop is ${ Laptop }. My favrite programming language is ${ Programmi...

JavaScript Program to swap two numbers without Third variable

  // Program to swap two numbers without Third variable // a=5;b=10; // b=5;a=10; let a = 5 ; let b = 10 ; [ a , b ] = [ b , a ]; console . log ( `the value a is change ${ a } and value b is changed ${ b }.` )

JavaScript Array and es6 example

  const myproglang = [ 'js' , 'php' , 'c' , 'python' , 'java' ]; // old javaScript style let h1 = myproglang [ 1 ]; console . log ( "My favrite programming language is " + "" + h1 ); // es6 advance javaScript Array Destructuring let [ a1 , a2 , a3 , a4 , a5 ] = myproglang ; console . log ( a4 ); console . log ( myproglang . length ); let [ top1 ,,,, toplast ] = myproglang ; console . log ( `My favrite programming language is ${ top1 } and my least favrite is ${ toplast }` );

JavaScript Do While Loop

 ------------------------------------------   index.html ---------------------------------------- <! DOCTYPE html > < html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < title > Document </ title > </ head > < body > < h1 > This is tutorial </ h1 > </ body > < script src = "Script.js" ></ script > </ html > ----------------------------------------- ------------------------------------------------ Script.js ------------------------------ console . log ( 'tutorial for while loop ' ) let k = 90 ; do { console . log ( k + 1 ); k += 1 ; } while ( k < 10 );