My Java Full Stack Journey Learning in JavaScript



This content originally appeared on DEV Community and was authored by Dinesh G

Fetch()

the fetch () function in javascript is a modern way to make a network request to the retrive data from the server or send data to the server.

Eg:

 fetch("https://fakestoreapi.com/products.json")
        .then((res)=>{
            return res.json();
            console.log("res");
        })
        .then(r) => log(r);
        .catch((error)=>{
            console.log("error");
        })  

Axios

Axios is popular promise based https client that simplifies asynchronous requests to external APIs

Eg

<script>
 axios.get("https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js")
    .then((res)=> console.log("res"))
    .catch((error)=> log("error"))
    </script>

closure

It is a inner function remember variable from it creation closure inner function access to outer function is an returns.

Eg:

function account(amount){
let balance = amount;
function withdraw (amt){
balance = balance.amt;
console.log(balance):
}
return withdraw;
}
const withdraw 1=account(1000);
withdraw 1(50);
const withdraw 2=account(500);
withdraw 2 (100);

Happy coding…


This content originally appeared on DEV Community and was authored by Dinesh G