DEV Community

Sathish K
Sathish K

Posted on

Closure,Fetch and Axios in javascript

what is the closure ?
The closure is used the inner function are remembers the variables was created. The inner function is access to outer is an return.

It is the combination function.

function account(amount){
    let balance =amount;
    function withdraw(atm){
        balance=balance-atm;
        console.log(balance);

    }
     return withdraw;

    }
    const withdraw1=account(1000);
    withdraw1(50);
    const withdraw2=account(500);
    withdraw2(100);
    withdraw2(50);
Enter fullscreen mode Exit fullscreen mode

*What is the Fetch ? *

Fetch() in javaScript is a returns the promise.
It is a make the network resource.
It is a response for server of "URL".

fetch("https://fakestoreapi.com/products")
.then((res)=>res.json())
.then((json)=>console.log(json))

 .catch((err)=>console.log(err))

Enter fullscreen mode Exit fullscreen mode

What is the axios ?
It is the libary platform and its open source "URL" server.
Axios is already convert the JSON mood.
It is used for HTTP request from both broswer and node.js environment.

axios.get("https://fakestoreapi.com/products")
            .then((res) => console.log(res))
            .catch((err) => console.log(err))

Enter fullscreen mode Exit fullscreen mode

Top comments (0)