I'm new to asynchronous javascript. I realise that code A works the same as code B.
Code A:
const name = ['a','b','c'];
setTimeout(()=>{
console.log(name);
},1500)
Code B:
const name = ['a','b','c'];
setTimeout(list=>{
console.log(list);
},1500,name)
- Should we go with Code A or Code B, which is better in terms of asynchronous?
- If we can use the variables that are declared outside setTimeout() directly in the setTimeout(), Why should we passing them into setTimeout() as third or fourth, etc parameters?