Interview questions for web(javascript) developers

webdevelopment

In todays post we are going to cover basic javascript questions that you might get in an interview after getting some industry experience.
webdevelopment
So here goes…

Q1. What are prototypes in javascript?
Ans.All javascript objects inherit the properties and methods from their prototypes.
IMP:All JavaScript objects (Date, Array, RegExp, Function, ….) inherit from the Object.prototype.
You can always give an example of creating a prototype as follows:

Q2. What are closures in javascript?
Private variables can be made possible in javascript with closures.
A closure is a function having access to the parent scope, even after the parent function has closed.In JavaScript, if you use the function keyword inside another function, you are creating a closure.
Example:

The above function will also log 16, because bar can still refer to x and tmp, even though it is no longer directly inside the scope.
However, since tmp is still hanging around inside bar’s closure, it is also being incremented. It will be incremented each time you call bar.

Q3.If you do not write var before writing a variable within a function what will be the consequences?
Ans. The variable will have a global scope even if it is written within a function.

Q4.What are anonymous functions in javascript?
Ans. Anonymous functions are functions are functions without a name in javascript.
Ex.

Q5. What are self invoking functions in javascript?
Ans. A self-invoking expression is invoked (started) automatically, without being called.
Function expressions will execute automatically if the expression is followed by ().

Q6. What are webworkers in javascript?
When executing scripts in an HTML page, the page becomes unresponsive until the script is finished.
A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.
Ex: Main script

samplework.js

Expect a few follow up questions about defining and running web workers.

Q7. What are events in javascript?
Ans. Event handlers can be used to handle, and verify, user input, user actions, and browser actions.
Some common events are onclick,onchange,onmouseover,onmouseout,onkeydown and onload.

Q8. Difference between window.onload and $(document).ready() method?
Ans.The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.
The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds functionality to the elements in the page doesn’t have to wait for all content to load.

Q9.What are new features in HTML5?
There are many new elements in HTML5 in terms of structural,form,graphics and media elements.
Examples:header,footer,main
Input types like color,date,datetime,email
Graphics elements like svg,canvas
Media elements like audio,video
Expect a few follow up questions on canvas or svg.

Q10.Preferred way to center a div in html
Ans.I generally prefer flexbox method in which parent div has following css properties:

Expect a few trick questions on Css properties

Q11.Difference between ‘==’ and ‘===’ in javascript?
The equality operator == does type conversion, meaning that the interpreter implicitly tries to convert the values before comparing.

On the other hand, the identity operator === does not do type conversion, and thus does not convert the values when comparing.
Ex:

Other than this questions prepare yourself for a few questions in responsive design and bootstrap framework since they are quite common nowadays.
Image source:Google images

Share post-
About Saurabh Mhatre 70 Articles
Currently working in web and hybrid application development