DEV Community

Discussion on: Syntactical Overkill in JavaScript

Collapse
 
pat_metzdorf profile image
Patrick Metzdorf

Nice article!

Quick tip: In your pre-ES2015 callApi() example, token and type would have to be defined above the function call, to be equivalent to the first version.
Otherwise they exist only inside your callback. ;)

e.g.:

var token
var type

callApi(function(response) {
  token = response.token;
  type = response.type;
})
Enter fullscreen mode Exit fullscreen mode
Collapse
 
iglosiggio profile image
Ignacio Losiggio

The thing is that you can't use token and type in the body of the caller of callApi bc you don't know if the callback was called and it's side-effects were produced.