0% found this document useful (0 votes)
8 views

Javascript Interview Questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Javascript Interview Questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JavaScript Interview Questions

1. What is js
JS is single threaded programming language basically for interactive and dynamic
content. It run each and every line one by one. Used in both client and server side.
Js modifies the code in dom
2. DOM
Dom represents web pages as tree like structure
html allows javascript to dynamically render the content and structure of a web page.
3. Event loop in js
Functions in JavaScript are executed in a synchronous manner, one after the
other.
To perform asynchronous operations without freezing the application
Item is added to the call stack and executed
The eventloop detects that the call stack is empty so it takes the callback from
the queue and pushes it to the call stack
4. Scope
Block Scope: reference error block outside
Function Scope:
5. Event delegation
Handling events on parent elements for multiple child elements. Instead of
adding an event listener to each and every child, add the event listener to the
parent. Efficiency
6. Event Bubbling
Event bubbling is the process when a mouse click or keypress happens on div element
in a webpage and then moves up through its parent elements. Parent to root.
To avoid event bubbling use event.stoppropagation.
7. Event capturing
Event capturing is the process when a mouse click the browser starts from top of dom
tree and move downwards to the target element.
8. Diff b/w DOM and Virtual DOM
DOM Virtual DOM

Refresh whole layout Creates dom copy at backside and virtual dom at
front shows the result
9. Hoisting in javascript
Access the variables and function even before initialization without any error.
10. How Hoisting works
Memory is allocated for each and every variable and function before the code start
executing. Memory allocate as undefined.
Global execution context is created and runs the program and context is deleted.
Hoisting occurs only in var. Let and const hoisting can be in temporal dead zone.
11. Function naming
● Named Function
● Anonymous function
● Arrow function
● Function expression
12. Return statement
Return statement stops the execution of a function and returns a value.
Makes the function reusable we use this in multiple
13. Not Defined and undefined
Not Defined undefined

Not Declared not initialized Declared but not initialized

14. Shallow Copy and Deep Copy


Shallow Copy Deep Copy

Shallow copy creates new object, but it does Deep copy creates entirely separate copy
not create copies of nested object. object and nested objects
Changes in nested object will affect original.
…… json.parse,json.stringify
Spread operator, object.assign

15. == and ===


== ===

check the two variables check the two variables and their data types

16. Callback Function


A function that is passed as an argument to other function and performing their
operations.

17. Data types in js


8 data types in javascript
7 data types are primitive
● Object - employee={name: ramya} //key : value key based


○ for in loop for(let data in employee) { data}
● Array - ordered collection or index [“apple”(index 0),”banana”(index 1)]
○ For of loop for(let data in array){data}
18. Types:
typeof(arr) = object
typeof(null) = object
typeof(undefined) = undefined
typeof(NaN) = number

19. Call, bind and apply


Call Bind Apply

Immediately invokes function Used to create new Immediately invokes function


with specified this and parsing function with ‘this’ keyword with specified this and parsing
arguments individually. arguments as array.

20. Inheritance:
Inheritance allows us to create child objects share common features from parent object.
Inherit properties from other object
21. Promise:
Promise represents the eventual completion or failure of an asynchronous operation.
It can be handled by then and catch then for resolved and catch for rejection
22. async/await:
Async is a keyword used to create async function and await ia also a keyword that
cannot be accessed without the async keyword await act like suspending the code
within the function.
23. Fetch Api
Fetch api is making http requests to servers, fetching data asynchronously. alternate to
xmlhttprequest(XHR)
24. Axios
Axios is js library used for making http request in web browsers. Support features like
interceptors, promise based requests, automatic transformation of request and
response data.
25. Interceptors
Interceptors act as middleware functions that intercept HTTP requests or responses
before they reach your application or server. They provide a way to inject custom logic
at various stages of the HTTP request/response lifecycle.
26. Closures:
A function along with its lexical scope, hierarchy of the scope keep maintaining it.
settimeout(),currying, iterators,
27. setTimeout
Execute a function in a specified amount of time i.e., This function calls function after
duration milliseconds from now. This goes for one execution.
Syntax:
setTimeout(function, delay)
setTimeout(alert(“Hello”), 1000);
28. setinterval
Repeatedly execute function at specified intervals. This function calls function after
every duration milliseconds. This goes for unlimited times.
Syntax:
setInterval(function, delay)
setInterval(alert(“Hello”), 1000);
29. diff b/w promise and callback
Callback Promise

Handling asynchronous operations passed Handling asynchronous operations 3 steps


arguments to other function pending fulfilled or rejected

Pass 2 parameters 1 for result and for error Built in error handling then and catch for
result and error

30. prototype how it works


Inherits properties from other objects. Every object in js has prototype. When we acess
property or method from js it looks in the object itself. If does not find it looks the object
prototype.
Syntax
Person.prototype
object.create()
31. Currying
Function performing sequence of function each taking single argument. The curried
function allows partial partial application of arguments. You call the function with some
of the arguments and get a new function that expects the remaining arguments.
32. Composition polyfill
Two or more functions are combined to produce a new function.
33. Promise.all
Takes more no of promises and return a single promise. It checks all the promises if it is
fulfilled i.e resolved. Any of the promise rejected it failed.
34. debounce
Debouncing is mainly for time consuming tasks making them more efficient. Delay the
execution of function until after certain amount of time has passed since the lasttime the
function was invoked.
handling search inputs, autosave functionalities.
27. Template literal
Template literal provide an easy way to interpolate variables and expressions
into strings.
Interpolation like concate
Es6 features more flexible and string interpolation in js
Use (``) instead of “”
Wecan use inside the text with ${}
28. Function type
Function Declaration function statement
● Function a(){console.log(“function”)}
Function Expression
● Var x = Function{console.log(“function”)} x
NamedFunction
● Var x = Function a(){console.log(“function”)} x
Anonymous function
● Function(){console.log(“function”)}
● Function x(parameter,parameter)
x(arg(10),arg(2))
Arrow function
● Function x = () => {}

29. Memoization
Technique to make function faster by remembering the previous results.
Stores the results and return them
Instead of recalculating every time a function is called with same inputs.
Tips:
● Try to create function in variables eg: let ram = func(){}
● Use eg: log(“name:” name + age) => log(`name: ${name} ${age})
let carfun = function(name,age){
console.log("name:" + name , "age:" + age);
console.log(`name: ${name}, age: ${age}`);
return `name: ${name}, age: ${age}`
}
let result = carfun("Ramya",45)
console.log(result);

You might also like