Thursday, January 29, 2015

Javascript Interview Questions

Question: What are Promises?

Promise is a proxy object for an event that is not necessary yet happened. A success and failure callback functions can be given to a promise, and once the promise is resolved (i.e. the 'promised' event happens successfully) or rejected (the 'promised' event fails), the corresponding callback gets called.
To access an object's promise, the then method is called.

Question: What does setTimeOut() do?

  • setTimeout() - executes a function, once, after waiting a specified number of milliseconds

Question: What is closure?

This will always alert 16, because bar can access the x which was defined as an argument to foo, and it can also access tmp from foo.
That is a closure. A function doesn't have to return in order to be called a closure. Simply accessing variables outside of your immediate lexical scope creates a closure.


Question: Write a function that combines two arrays into one?


Q: What is a callback? Callbacks are a more traditional way of handling asynchronous execution in JavaScript. A callback is a function that is passed to another function as a parameter, and the execution of the callback happens inside the function that it was passed to.


No comments: