Last active
September 10, 2018 17:32
-
-
Save ajaynitt/c26a5fba548c46a6cc46248a0fa8af94 to your computer and use it in GitHub Desktop.
javascript interview questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1) | |
What are JavaScript Data Types? | |
Following are the JavaScript Data types: | |
Number | |
String | |
Boolean | |
Function | |
Object | |
Undefined | |
(2) Given a variable , how do we find which kind of variable it is ? (like Number , String) | |
Ans : typeof variableName | |
(3)Explain the difference between "==" and "==="? | |
"==" checks only for equality in value whereas "===" is a stricter equality test and returns false | |
if either the value or the type of the two variables are different. | |
(4)What is an undefined value in JavaScript? | |
Undefined value means the | |
Variable used in the code doesnot exist | |
Variable is not assigned to any value | |
Property doesnot exist | |
(5)What is the purpose of clearTimeout function? | |
(6)EventEmitter | |
Many objects in a Node emit events, for example, a net.Server emits an event each time a peer connects to it, | |
an fs.readStream emits an event when the file is opened. | |
All objects which emit events are the instances of events.EventEmitter. | |
(7)What Are Globals In Node.Js? | |
Answer. | |
There are three keywords in Node.js which constitute as Globals. These are Global, Process, and Buffer | |
(8) Difference between process.nextTick() and setTimeout | |
he difference between setTimeout() and process.nextTick() is that the process.nextTick() function is specific to the Node.js | |
Event Loop. setTimeout() uses JavaScript runtime to schedule its own queue of events. | |
When using process.nextTick(), callback function associated with it runs immediately after events in the Event Queue are | |
processed by the Event Loop in a single iteration. In comparison to setTimeout(), it is faster since queue | |
associated with setTimeout() | |
or the JavaScript runtime. | |
=========== | |
const server = net.createServer(() => {}).listen(8080); | |
server.on('listening', () => {}); | |
When only a port is passed, the port is bound immediately. | |
So, the 'listening' callback could be called immediately. The problem is that the .on('listening') | |
callback will not have been set by that time. | |
To get around this, the 'listening' event is queued in a nextTick() to allow the script to run to completion. | |
This allows the user to set any event handlers they want. | |
=========================== | |
(9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment