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

JavaScript Questions

Uploaded by

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

JavaScript Questions

Uploaded by

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

1. What is JavaScript? How does it work?

● JavaScript is a programming language for web development. It


runs in web browsers and makes web pages interactive by
handling events, manipulating the DOM, and more.
2. What is an asynchronous operation? Is JavaScript synchronous or
asynchronous?

Async :- Wait for a response until the response is resolved.


By default js is synchronous, it executes the code line by line.

● Asynchronous operations in JavaScript are tasks that run


separately from the main program flow, allowing other code to
execute while waiting for them to complete. JavaScript is both
synchronous and asynchronous.
3. Explain async using setTimeout.
It waits for the particular time after a certain time the code will execute.
● setTimeout in JavaScript delays the execution of a function for a
specified time, allowing other code to run in the meantime.
4. Is JavaScript single-threaded or multi-threaded?
● JavaScript is single-threaded, meaning it can only execute one
task at a time.
5. Is JavaScript an asynchronous or synchronous language?
● JavaScript is both asynchronous and synchronous, as it can
handle both types of operations.
6. Difference between var, let, and const.
● var is function-scoped, while let and const are block-scoped
variables in JavaScript.
7. What is hoisting?
Try to access the function or variable before declaration .
● Hoisting moves variable and function declarations to the top of
their containing scope during compilation in JavaScript.
8. What is a promise? What are the states of promises? What is promisify?
● A promise in JavaScript represents the eventual completion or
failure of an asynchronous operation, having states: pending,
fulfilled, or rejected. Promisify converts callback-based functions
into promise-based ones.
9. What is async/await?
● Async/await is a modern JavaScript feature that allows writing
asynchronous code in a synchronous-looking manner, improving
code readability.
10. Difference between promise and async & await. Is async/await notation
preferred over promises? If so, why?
● Both handle asynchronous operations, but async/await offers a
cleaner and more organized syntax, making code easier to read
and maintain. Async/await is generally preferred.
11. What are JavaScript Objects? How to create them?
● JavaScript objects are collections of key-value pairs. They can be
created using object literals {}, constructor functions, or classes.
12. How to search for a value or a key in an object?
Ans :- .containsKey()
● Use methods like Object.keys(), Object.values(), or
Object.entries() along with indexOf() or includes() to
search for a value or key in an object.
13. What is a callback function?
It is passed as a parameter in another function and it execute after
certain amount of time.
We use callback function if we want to use asynchrounus function.
● A callback function in JavaScript is a function passed as an
argument to another function, executed later when a certain
condition is met or an asynchronous operation completes.
14. What are the drawbacks of callbacks and what is callback hell?
● Callbacks can lead to callback hell, where nested callbacks make
code hard to read and maintain, resulting in spaghetti code.
15. Difference between callback and promise. How can you write the same
async operation using promise and callback?
● Promises provide a cleaner and more organized way to handle
asynchronous operations compared to callbacks, reducing
callback hell. They're easier to chain and manage.
16. Difference between function and arrow function.
● Arrow functions in JavaScript are a more concise way to write
functions, with implicit return and lexical this binding.
17. Difference between i++ and ++i.
● i++ returns the current value of i before incrementing it, while +
+i increments i first and then returns the updated value.
18. What is the “this” operator?
● The this keyword in JavaScript refers to the current object or
context in which a function is called.
19. What is the closure concept?
● Closure in JavaScript allows a function to remember and access
its lexical scope, even when executed outside that scope.
20. What is JSON? What do json.parse and json.stringify do?
● JSON (JavaScript Object Notation) is a data format used for
exchanging data. JSON.parse() converts a JSON string to a
JavaScript object, while JSON.stringify() converts a JavaScript
object to a JSON string.
21. What is the difference between '==' and '===' operators?
● == checks for value equality with type coercion, while === checks
for both value and type equality.
22. What is the type of operator? What is NaN?
● The typeof operator in JavaScript returns the data type of its
operand. NaN stands for "Not a Number" and is returned when a
mathematical operation produces an invalid number.
23. What are setTimeout and setInterval functions and what is the
difference between them?
● setTimeout and setInterval are functions used to delay code
execution or repeatedly run code at intervals. The difference is
that setTimeout executes code once after a delay, while
setInterval repeatedly executes code at specified intervals.
24. What is functional scope and block scope?
● Functional scope refers to the scope created by functions, while
block scope refers to the scope created by blocks enclosed in
curly braces {}.
25. What is shallow copy and deep copy?
● Shallow copy creates a new object with the same properties as
the original object, while deep copy creates a new object with its
own copy of nested objects.
26. What is the difference between map and filter? Explain math
functionalities.
● map() transforms each element of an array using a provided
function, while filter() creates a new array with elements that
pass a test specified by a callback function.
27. What is ES6? Explain some features of ES6.
● ES6 (ECMAScript 2015) is a version of JavaScript introducing
features like arrow functions, classes, template literals, and
destructuring assignment.
28. Difference between TypeScript & JavaScript.
● TypeScript is a superset of JavaScript, adding static typing and
other features for large-scale application development.
29. What is regex?
● Regex (regular expression) is a sequence of characters that
forms a search pattern, used mainly for pattern matching in
strings.
30. What are first-class functions?
● First-class functions in JavaScript means functions are treated as
first-class citizens, allowing them to be passed around as
arguments, returned from other functions, and assigned to
variables.
31. Difference between primitive and reference data types.
● Primitive data types in JavaScript are immutable, while reference
data types are mutable and stored by reference in memory.
32. Difference between null and undefined.
● null represents the intentional absence of any object value, while
undefined indicates that a variable has been declared but not
assigned a value.
33. Difference between slice and splice.
● slice() returns a shallow copy of a portion of an array into a new
array without modifying the original array, while splice()
changes the contents of an array by removing or replacing
existing elements.
34. What is spread operator and rest operator?
● Spread operator (...) spreads elements of an iterable like arrays
into individual elements, while rest operator ( ...) gathers
elements into an array.
35. How to convert integer to string and string to integer?
● Use toString()

You might also like