10 tricky interview question for js developer.
- What is Java Script ?
2.What are the features of JS?
The features of java script are dynamic typing , DOM manipulation , platform independent , functional style , prototype base , OOP support , async processing ,handling date and time , case sensitive format, handling event and light weight .
3.What is truthy and falsy values?
Truthy Value :string is true other than empty string (“”) , any number is true other than 0 .
Falsy Value : Undefined , null , 0 , NaN ,empty string (“”), false.
4. Null vs Undefined .
Null : Null means not existing or empty .
Undefined : Undefined means variable has been declared but value has not been assigned or initialized.
5. Difference between double equal (==)and triple equal(===)?
Here triple equal operator is strict equality operator because it compare value and type of value , while double equal operator is just equality operator .
6. What is function scope ?
Function scope : Variable declared inside the function is called function scope . Look at example below , a total variable only will be accessible within the function but can not access from outside.
7.What is block scope in js ?
Block Scope : Variable with var keyword can not be block scope . If a variable declared with using let and const keyword inside curly braces then it’s called block scope . This variable can not be access from outside.
8.What is closure ?
As per the closure definition, if inner function access the variables of outer function then only it is called closure.
If a function returns a function or if inside a function got a function then it creates a closed environment, Means it can access the variable from parent scope. This is called closure.
9. What is bind method?
10. What is DOM?
DOM stands for document object model. This is platform and language neutral interface which allows the programs or scripts to dynamically modify the or update the style ,content and structure of documents.
11.Typeof operator: ‘ Typeof’ is an operator used to return a string description of the type of a variable.
12.Callback function : Functions that are used as an argument to another function are called callback functions. Callback is a function that will be executed after another function gets executed.
13.What is function : Function is a block of which which perform a particular task.
14.The rest parameter (…) allows a function to treat an indefinite number of arguments as an array
15. Default parameter :This allows us to give default values to function parameters.
16.The Difference Between Arrays and Objects
Arrays are a special type of objects, with numbered indexes.
17. What is map ?
map() method creates a new array with the results of calling a function for every array element.
map() method calls the provided function once for each element in an array, in order.
18. map vs forEach ?
map returns a new array.
forEach has no return value.
That’s the heart of the difference. Most of the other answers here say effectively that, but in a much more convoluted way.
Why should you use map rather than forEach ?
- Just about anything you can do with
forEach()you can do with
map(), and vise versa.
map()allocates memory and stores
forEach()throws away return values and always returns
forEach()will allow a callback function to mutate the current array.
map()will instead return a new array.
19.setTimeout(function, milliseconds ) Executes a function, after waiting a specified number of millisecond.
20.Scope determines the accessibility (visibility) of variables.
21.Difference between find and filter
- filter() method search through all the elements. return an array
- find() method search through all the child elements only. return an object
For example: If you use it in a form element, it prevents it from submitting. If used in an anchor element, it prevents it from navigating. If used in a contextmenu, it prevents it from showing or displaying.
On the other hand, the event.stopPropagation() method is used to stop the propagation of an event or stop the event from occurring in the bubbling or capturing phase.
24.What is negative infinity?
Negative Infinity is a number which is result of dividing a negative number by zero.
25.Function with default parameters :In java script default function parameters allowed named parameters to be initialized with default value if parameter value is missing . So it’s better to pass default value .