JavaScript
JavaScript
Q2. What are data types in JavaScript? What are primi ve data types?
A data type determines the type of the values that can be stored in a
variable. They can only hold single value.
Primi ve data types are immutable, which means that their values
cannot be changed or modified once they are created.
Q5. What is the difference between var, let, and const in JavaScript? V. IMP.
var creates a func on-scoped variable.
let creates a block-scoped variable
const can be assigned only once, and its value cannot be changed
a erwards.
Q6. What is loop? What are the type of loops in Javascript?
A loop is a programming way to run a set of instruc ons(code)
repeatedly un l a certain condi on is met.
Q7. What is the difference between for, while and do-while loops?
For loop allows to iterate a block of code a specific number of mes.
While loop execute a block of code while a certain condi on is true
The do-while loop is similar to the while loop, except that the block of
code is executed at least once, even if the condi on is false.
1. Named func on
When there is a name of the func on that func on is called a
named func on.
2. Anonymous func on
Func on with no name is called Anonymous func on.
Q13. What is func on expression in JavaScript?
A func on expression is a way to define a func on in JavaScript by
assigning it to a variable.
This is useful for the Asynchronous opera ons are opera ons that do not block the execu on
function which take of the code.
more time to
complete, like setTimeout is the asynchronous func on which executes callback
fetching data from a
server, reading files, func on a er a specific period of me.
or waiting for a timer
to complete."
Q20. What are promises in JavaScript? V. IMP.
In javaScript promise is a good way to handle asynchronous opera ons.
It is used to find out if the asynchronous opera on is successfully
completed or not.
Promises have 3 States:
1. Pending
2. Fulfilled
3. Rejected
Q21. How to implement promises in JavaScript?
A promise is created
using the Promise
constructor, which takes
a function (executor) with
two parameters: resolve
and reject.
Q28. What is the type of a variable in JS when it is declared without using the
var, let, or const keywords?
"var" is the implicit type of variable when a variable is declared without
var, let, or const keywords.
Q32. What is the difference between unary, binary, and ternary operators?
Q33. What is the difference between Spread and Rest operator in JS?
The spread operator(...) is used to expand or spread elements from an
iterable (such as an array, string, or object) into individual elements.
The rest operator is used in func on parameters to collect all remaining
arguments into an array.
Q36. What is the difference between push() and concat() methods of an Array?
Push() will modify the original array itself.
Concat() method will create the new array and not modify the original
array.
Q37. What is the difference between pop() and shi () methods of an Array?
pop() will remove the last element of the array.
Shi () will remove the first element of the array.
Q40. What is the difference map() and forEach() array methods of an Array?
The map() method is used when you want to modify each element of an
array and create a new array with the modified values.
The forEach() method is used when you want to perform some opera on
on each element of an array without crea ng a new array.
Q44. What is the difference between break and con nue statement? V. IMP.
The "break" statement is used to terminate the loop.
The "con nue" statement is used to skip the current itera on of the loop
and move on to the next itera on.
Q45. What is the difference between arguments and parameters?
Parameters are the placeholders defined in the func on declara on.
Arguments are the actual values passed. to a func on when it is invoked
or called.
Q46. In how many ways can you pass arguments to a func on?
An impure func on, can produce different outputs for the same input.
Impure func ons can modify the state.
Impure func ons can have side effects.
Q50. What is Func on Currying in JS?
Currying in JavaScript transforms a func on with mul ple arguments into
a nested series of func ons, each taking a single argument.
Advantage: Reusability, modularity, and
specializa on, Big, complex func ons with mul ple arguments can be
broken down into small, reusable func ons with fewer arguments.
Q56. How do you select, modify, create and remove DOM elements?
Q57. What are selectors in JS?
Selectors in JS help to get specific elements from DOM based on IDs, class
names, tag names.
Q62. How to add and remove proper es of HTML elements in the DOM using
JS?
Q63. How to add and remove style from HTML elements in DOM using JS?
Q64. How to create new elements in DOM using JS? What is the difference
between createElement() and cloneNode()?
Q73. What are some common methods to iterate over the proper es of an
object?
Q76. What is the difference between deep copy and shallow copy in JS?
Shallow copy in nested objects case will modify the parent object
property value, if cloned object property value is changed. But deep copy
will not modify the parent object property value.
Q85. What is the use of "this" keyword in the context of event handling in JS?
"this" keyword refers to the element that the event handler is a ached
to.