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

JavaScript

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

JavaScript

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

JAVASCRIPT

Q1. What is JavaScript?


JavaScript is a programming language that is used for conver ng sta c
web pages to interac ve and dynamic web pages.

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.

Q3. What are arrays, func ons and objects? V. IMP.


 An array in is used to store a collec on of values, such as a list of
numbers or a list of names.
 A func on is a block of code that performs a specific task or returns a
value.
 An object is a non primi ve data type which can hold mul ple values or a
combina on of values and func ons.

Q4. What is scope in JavaScript?


 Local scope: Variables declared inside a func on have local scope, which
means they can only be accessed within the func on not outside.
 Global scope: Variables declared outside any func on have global scope,
which means they can be accessed from anywhere within a program.

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.

Q8. What is the difference between for...of and for...in loop?


 for...of loop is used to loop through the values of an object like arrays,
strings.
 It allows you to access each value directly, without having to use an
index.
 for...in loop is used to loop through the proper es of an object.
 It allows you to iterate over the keys of an object and access the values
associated with those keys.
Q9. What is forEach method? Compare it with for...of and for...in loop? V. IMP.
forEach is a method available on arrays or object that allows you to
iterate over each element of the array and perform some ac on on each
element.

Q10. What is the difference between == and === in JavaScript?


 == operator performs type coercion and converts the string to the
number and then compare.
 === operator does not perform type coercion and only set to true if
value and types both are same.

Q11. Difference between Primi ve and Non-Primi ve data Types.
Functions In JS:
Q12. What are the types of func ons in JavaScript? What are named and
anonymous func ons?

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.

Q14. What are Arrow Func ons in JavaScript? v. IMP.


Arrow func ons, also known as fat arrow func ons, are a concise syntax
for defining func ons in JavaScript.

Q15. What are Callback Func ons? V. IMP.


A callback func on is a func on that is passed as an argument to another
func on.
Q16. When to use Callback Func ons in real applica ons? V. IMP

Q17. What is the use of event handling in JavaScript?


Event handling in JavaScript allows you to interact with user ac ons (like
clicks, key presses, form submissions, etc.) and respond to those events
in your web applica on. It makes your web pages dynamic and
interac ve.
Q18. What is Higher-order func on?
A Higher order func on:
Take one or more func ons as arguments (callback func on) OR
Return a func on as a result

Q19. What are asynchronous opera ons in JavaScript? V. IMP.

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.

You can use .then() to


handle fulfilled
promises and .catch()
to handle rejected
promises.

Q22. When to use Promises in real applica ons?


Q23. What are the classes and objects in the JavaScript?

Q24. What is the purpose of "this" in JavaScript?


Q25. What is hois ng in JavaScript?
Hois ng in JavaScript is a behavior where variable and func on
declara ons are moved to the top of their scope before code execu on.
This means that you can use variables and func ons before they are
declared in the code. Variables declared with var are hoisted, Hoisting allows you to use
functions and variables before
they are defined in the code.

Q26. What is the role of javaScript Engine?


A JavaScript engine is a program present in web browsers that executes
JavaScript code.
Q27. What are Client side and Server side? V. IMP.
A client is a device, applica on, or so ware component that requests
and consumes services or resources from a server.
A server is a device, computer, or so ware applica on that provides
services, resources, or func ons to clients.

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.

Q29. What is the difference between null and undefined in JS?


undefined: When a variable is declared but has not been assigned a
value, it is automa cally ini alized with undefined.
Undefined can be used when you don't have the value right now, but you
will get it a er some logic or opera on.
null: null variables are inten onally assigned the null value.
Null can be used, when you are sure you do not have any value for the
par cular variable.

Q30. What is the use of typeof operator?


typeof operator is used to determine the type of each variable.
Real applica on use -> type Of operator can be used to validate the data
received from external sources(api).
Q31. What is type coercion in JS?
Type coercion is the automa c conversion of values from one data type
to another during certain opera ons or comparisons.
Uses of type coercion:
Type coercion can be used during String and Number concatena on.
Type coercion can be used while using Comparison operators.

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.

Q34. What are the methods of Array in JS?


Q35. What is the difference between find() and filter() methods of an Array? V.
IMP.
find() method get the first element that sa sfies a condi on.
filter() method get an array of elements that sa sfies a condi on.
Slice() method get a subset of the array from start index to end
index(end not included).

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.

Q38. What is the splice() method of an Array? V. IMP.


The splice() method is used to add, remove, or replace elements in an
array.
Q39. What is the difference between the slice() and splice() methods of an
Array?
The slice() method is used get a subset of the array from the start index
to the end index(end not included).
The splice() method is used to add, remove, or replace elements in an
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.

Q41. What is Array Destructuring in JS? V. IMP.


Array destructuring allows you to extract elements from an array and
assign them to individual variables in a single statement.
Array destructuring is introduced in ECMAScript 6 (ES6).
Q42. What are array-like objects In JS? V. IMP.
Array-like objects are objects that have indexed elements and a length
property, similar to arrays, but they may not have all the methods of
arrays like push(), pop() & others.

Q43. How to convert an array-like object into an 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?

Q47. How do you use default parameters in a func on?


In JavaScript, default parameters allow you to specify default values for
func on parameters.
Q48. What is the use of event handling in JS?
Event handling is the process of responding to user ac ons in a web
page.
The addEventListener method of Javascript allows to a ach an event
name and with the func on you want to perform on that event.

Q49. What are Pure and Impure func ons in JS?


A pure func on is a func on that always produces the same output for
the same input.
Pure func ons cannot modify the state.
Pure func ons cannot have side effects.

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.

Q51. What are call, apply and bind methods in JS?


call, apply, and bind are three methods in JavaScript that are used to
work with func ons and control how they are invoked and what context
they operate in.
These methods provide a way to manipulate the this value and pass
arguments to func ons.
Q52. What are template literals and string interpola on in strings? V. IMP.
A template literal, also known as a template string, is a feature
introduced in ECMAScript 2015 (ES6) for string interpola on and
mul line strings in JavaScript.

Q53. What are some important string opera ons in JS?


Q54. What is string immutability? V. IMP.
Strings in JavaScript are considered immutable because you cannot
modify the contents of an exis ng string directly.

Q55. In how many ways you can concatenate strings?

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.

Q58. What is the difference betweengetElementByld ,getElementsByClass


Name and getElementsByTagName? V. IMP.

Q59. What is the difference between querySelector() and querySelectorAll()?


Q60. What are the methods to modify elements proper es and a ributes?

Q61. What is the difference between innerHTML and textContent? V. IMP.

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()?

Q65. What is the difference between createElement() and createTextNode()?


Q66. What is the purpose of the throw statement in JS?
The throw statement stops the execu on of the current func on and
passes the error to the catch block of calling func on.

Q67. What is Error propaga on in JS?


Error propaga on refers to the process of passing or propaga ng an
error from one part of the code to another by using the throw statement
with try catch.

Q68. What are Objects in JS? V. IMP.


An object is a data type that allows you to store key-value pairs.
Q69. In how many ways we can create an object?

Q70. What is the difference between array and object?

Q71. How do you add, modify or delete proper es of an object?


Q72. Explain the difference between dot nota on and bracket nota on?
Both dot nota on and bracket nota on are used to access proper es or
methods of an object.
Dot nota on is more popular and used due to its simplicity.

Q73. What are some common methods to iterate over the proper es of an
object?

Q74. How do you check if a property exists in an object?


Q75. How do you clone or copy 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.

Q77. What is Set Object in JS?


The Set object is a collec on of unique values, meaning that duplicate
values are not allowed.
Set provides methods for adding, dele ng, and checking the existence of
values in the set.
Set can be used to remove duplicate values from arrays.

Q78. What is the difference between Map and Object in JS?


Q79. What are Events? How are events triggered?
Events are ac ons that happen in the browser, such as a bu on click,
mouse movement, or keyboard input.

Q80. What is Event Object in JS?


Whenever any event is triggered, the browser automa cally creates an
event object and passes it as an argument to the event handler func on.
The event object contains various proper es and methods that provide
informa on about the event, such as the type of event, the element that
triggered the event etc.
Q81. What is Event Delega on in JS? V. IMP.
Event delega on in JavaScript is a technique where you a ach a single
event handler to a parent element to handle events on its child
elements.

Q82. What is Event Bubbling In JS? V. IMP.


Event bubbling is the process in JavaScript where an event triggered on a
child element propagates up the DOM tree, triggering event handlers on
its parent elements.

Q83. What is Event Capturing in JS?


Event capturing is the process in JavaScript where an event is handled
star ng from the highest-level ancestor (the root of the DOM tree) and
moving down to the target element.
Q84. What is the purpose of the event.preventDefault() method in JS?
The event.preventDefault() method is used to prevent the default
behavior. of an event and the link click will be prevented.

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.

Q86. How to remove an event handler from an element in JS?


removeEventListener() method is used to remove event handler from
element.

You might also like