Thursday 10 February 2022

Nodejs - Prototype

 prototype = provide ability for adding new methods or class (Example- Inherit)


1) Home.js

var cal = require("./addition");
cal.addition();
console.log(cal.aval)

2) addition.js

module.exports={
    addition:function(){
        console.log("this is addition module");
    },
    aval:20
}


o/p ->

this is addition module

20


Nodejs- Templete String

 var name ="kamal"

var age = "26"


console.log("value of %s and %s",name,age)

//or

console.log("value one: "+name+"value two: "+age)

//now templete string example is...
console.log(`name ${name} age ${age}`)

Nodejs - Class Example

  Class Example

class users{                         ///creteing class

        constructor(name,age){              //declare constructor
            this.name =name;
            this.age=age;
        }
   
        getName(){
            this.email ="dev@gmail.com";
            return this.name;
        }

        getAge(){
            return this.age;
        }

        getEmail(){
            return this.email;
        }
}

///now crete object of class
var user = new users("kamal","26");
console.log(user.getName())
console.log(user.getAge())
console.log(user.getEmail()) ///agar getName() function define ne rhege pahle to undefine k error ayega



OUTPUT
kamal 26 dev@gmail.com




Wednesday 9 February 2022

Nodejs - ECMA Concept

ECMA Concept

-> 'let ' is an scope varible it can't be use as globle varible

-> if we'r using 'var' in place of let it will re-assign last defined value (means

    var a = 30

    var a = 30

    console.log("value of a is:"+a)

OUTPUT-

        value of a is = 30

)

if we are using 'let' inplace of var then it look like

let a=40;

let a=30;

OUTPUT

SyntaxError: Identifier 'a' has already been declared

    at wrapSafe (internal/modules/cjs/loader.js:1001:16)

    at Module._compile (internal/modules/cjs/loader.js:1049:27)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

    at Module.load (internal/modules/cjs/loader.js:950:32)

    at Function.Module._load (internal/modules/cjs/loader.js:790:12)

    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)

    at internal/main/run_main_module.js:17:47 


if we using scope varible

let a=30;


function esma_example(){
    let a = 40;
    console.log("value of a under function :"+a);
}

esma_example()
console.log("value of a:"+a);


output-

value of a under function :40

value of a:30


Nodejs- module exports

module exports

->it will help to get/fetch one module data into another module

main.js 

var name = "Kamal"
var person = function(a,b){
    var c = a+b
    console.log("sum of "+ a +" and "+ b +" is "+ c)
}

person(5,5);

module.exports.exp_example = name;


global_object.js

var main = require("./main")
console.log(__dirname)
console.log(__filename)
console.log(main.exp_example)


OUTPUT-

K:\NodeJs\Node Basics\chapter-1

K:\NodeJs\Node Basics\chapter-1\globalObject.js

Kamal

Nodejs - Global Objects

 Global Objects

-> We have two js files for accessing main.js objects we are using this functions in object.js

1)main.js

var person = function(a,b){
    var c = a+b
    console.log("sum of "+ a +" and "+ b +" is "+ c)
}

person(5,5);

2)global_objects.js

var main = require("./mian")
console.log(__dirname)
console.log(__filename)


output
sum of 5 and 5 is 10 K:\NodeJs\Node Basics\chapter-1 K:\NodeJs\Node Basics\chapter-1\globalObject.js




Nodejs - Arrow Functions

Arrorw Functions :
    
        -> Its a shortest way to define functions.

             EXAMPLE:    
            
            Without Parameter

                    var kamal =()=>{console.log("Its a arrow functions")}
                   
                     kamal()            ///call function

            With Parameter

                    var kamal =(a)=>{console.log("value of a is :"+a)}
                    
                    kamal(5)          ///call function

            With Multiple Parameter

                    var kamal =(a,b)=>{
                                
                    var  c=a+b
                    console.log("value of c is :"+c)}
                    
                    kamal(5,5)          ///call function

OUTPUT- value of c is :10

Nodejs - Anonymous Functions

 Anonymous Functions

    -> define variable then function

    Ex.-        !) Without parameter.... 

                     ver kamal = function(){

                        console.log("Its a anontmous function");

                    }

                    kamal()              ///call functions


                !!) With parameter...

                    var kamal = funtion(a,b){

                     var c = a+b

                    console.log("The value of  c is : "+c)

                     }


                    kamal(5,5)          //call functions


OUTPUT -  The value of  c is :10

NOTE: There is no name infront of function thats why its a anonymous function.



Kotlin - Observer

 Rxjava -  Observer - Based on data view willl render (react) karega. trotling -> making stream for execution (Means clicks event fire kr...