JS Interview Question
JS Interview Question
JS Interview Question
1. What is JavaScript?
Ans: JavaScript is a high-level programming language, It’s also a popular web scripting
language that’s used for client-side and server-side development. JavaScript can be inserted
into HTML pages and executed by web browsers. It allows developers to add interactivity,
dynamic content, and behavior to websites.
Ans: JavaScript has several built-in data types that allow you to store and manipulate different
kinds of values. There are three major Data types in JavaScript.
1. Primitive
● Numbers
● Strings
● Boolean
2. Symbol
● Trivial
● Undefined
● Null
3. Composite
● Objects
● Functions
● Arrays
Ans: In JavaScript, a variable is a named container that stores a value. It allows one to assign
values to a symbolic name and refer to that name to access the stored value. Variables in
JavaScript are dynamically typed, which means it can assign values of different data types to
the same variable.
Ans: Global variables are available throughout the length of the code so that it has no scope.
The var keyword is used to declare a local variable or object. If the var keyword is omitted, a
global variable is declared.
5. How to comment out in JavaScript?
Ans: Comments are used to prevent the execution of statements. Comments are ignored while
the compiler executes the code.
There are two types of symbols used to represent comments
Multi-line comment: /*
Multi-line
Comment
*/
Ans: (==) operator checks for equality between two values, performing type coercion if
necessary. It compares the values without considering their data types and attempts to convert
them to a common type before making the comparison.
(===) operator checks for equality between two values without performing type coercion. It
compares both the values and their data types, ensuring that both the values and types are
identical for the comparison to be true.
Ans: Cookies are the small test files stored in a computer, and they get created when the user
visits the websites to store information that they need. Examples could be User Name details
and shopping cart information from previous visits.
Ans: The pop() method is similar to the shift() method, but the difference is that the Shift method
works at the array’s start. The pop() method takes the last element off of the given array and
returns it. The array on which it is called is then altered.
11. What is the use of the Push and unshift method in JavaScript?
Ans: The push method is used to add or append one or more elements to an Array end. Using
this method, we can append multiple elements by passing multiple arguments.
Unshift method is like the push method, which works at the beginning of the array. This method
is used to prepend one or more elements to the beginning of the array.
12. What are the different types of errors in JavaScript?
Ans: There are three types of errors:
1. Load time errors: Errors that come up when loading a web page, like improper syntax
errors, are known as Load time errors and generate the errors dynamically.
2. Runtime errors: Errors that come due to misuse of the command inside the HTML
language.
3. Logical errors: These are the errors that occur due to the bad logic performed on a
function with a different operation.
Ans: The break statement is used to come out of the current loop. In contrast, the continue
statement continues the current loop with a new recurrence.
Ans: DOM stands for Document Object Model and is responsible for how various objects in a
document interact with each other. DOM is required for developing web pages, which include
objects like paragraphs, links, etc. These objects can be operated to include actions like add or
delete. DOM is also required to add extra capabilities to a web page.
73. How are event handlers utilized in JavaScript?
Ans: Events are the actions that result from activities, such as clicking a link or filling out a form
by the user. An event handler is required to manage the proper execution of all these events.
Event handlers are an extra attribute of the object. This attribute includes the event’s name and
the action taken if the event takes place.
Ans: Using DOM, JavaScript can perform multiple tasks. It can create new elements and
attributes, change the existing elements and attributes and even remove existing elements and
attributes. JavaScript can also react to existing events and create new events on the page.
getElementById, innerHTML Example
getElementById: To access elements and attributes whose id is set.
innerHTML: To access the content of an element.
Javascript ES6 Question and Answer
Ans: ES6, also known as ECMAScript 2015, is a significant update to the ECMAScript
specification, which forms the basis of JavaScript. It introduced several new features and
enhancements to the language, greatly expanding its capabilities and improving developer
productivity.
Ans: ES6 introduced numerous features and improvements to the JavaScript language. Below
are the common features of ES6…
3. What are let and const? How both are different from var?
Ans: In JavaScript user can declare any variable using the var keyword. Var keyword is function
scoped. It can access the variable within a function. This leads to wrapping the code in a
function whenever we had to create a new scope.
Let and const both are blocks scoped. If you declare a variable using these keywords then it
only exists within the innermost block that surrounds them.
4. What is the Arrow function? What is the difference between a normal function and an
arrow function?
Ans: The arrow function was introduced in ECMAScript 2015 (ES6) for defining functions in
JavaScript. It provides a more compact and streamlined way to write functions compared to
traditional function expressions.
● Syntax: Arrow functions have a more concise syntax compared to normal functions. The
arrow function is defined using the arrow (=>) operator, while normal functions use the
function keyword.
● Arguments Object: Arrow functions do not have their own arguments object. Instead,
they inherit the arguments object from the enclosing scope.
Ans: This is a new feature in ES6. The generator function allows you to generate many values
over time, returning an object. We can iterate this object, and we can pull values from the
function one value at a time. When you call a generator function it returns an iterable object. We
use the * sign for a generator function with a new ‘yield’ keyword in ES6.
Ans: Spread operator is used to obtain the list of parameters. It is represented by three dots
(…). Basically spread operator takes an iterable and expands it into individual elements. In
JavaScript, it is mainly used to make shallow copies of JS. It makes code concise and increases
the readability of your code.
Ans: Destructuring in ES6 provides a concise way to extract values from arrays or objects,
assigning them to variables using matching patterns. It makes code easier to read, avoids
repetition, and simplifies working with complex data structures.
Ans: In ES6 (ECMAScript 2015), the Map is a built-in data structure that allows to store
key-value pairs. It provides a collection of unique keys and their corresponding values, similar to
an object. However, unlike objects, Map allows any value to be used as a key and preserves the
original insertion order of elements.
Ans: It is introduced in ES6 which improves the ability to handle the parameters. With rest
parameters, it is possible to represent indefinite parameters as an array. By using the rest
parameter, we can call a function with any number of arguments.
10. How to create a class in ES6?
Ans: This keyword is used for creating the class. We can include the classes in our code either
by using class expression or by class declaration. A class definition can only include functions
and constructors. These components are together called data members of the class.
for...of loop is used for iterating the iterables (arrays, string, etc.).
Ans: It is used to handle the execution of a function after the completion of the execution of
another function. A callback would be helpful in working with events. In the callback, a function
can be passed as an argument to another function. It is a great way when we are dealing with
basic cases such as minimal asynchronous operations.
Ans: There are four string methods introduced in ES6 that are listed as follows:
● string.startsWith()
● string.endsWith()
● string.includes()
● string.repeat()
Ans: There are many array methods available in ES6, which are listed below:
● Array.of()
● Array.from()
● Array.prototype.find()
● Array.prototype.findIndex()
● Array.prototype.entries()
● Array.prototype.keys()
● Array.prototype.values()
● Array.prototype.fill()
15. Discuss the Rest parameter in ES6 with an example.
Ans: It is introduced in ES6 which improves the ability to handle the parameters. With rest
parameters, it is possible to represent indefinite parameters as an array. By using the rest
parameter, we can call a function with any number of arguments.
What is the difference between regular function and arrow function?
- What is DOM?
- What are the different ways to get an element from DOM?
- What’s the difference between an Event Handler and an Event Listener?
- What does “event bubbling” mean in JavaScript?
- Can you explain the different types of events available in JavaScript?
- What’s the difference between event.preventDefault() and event.stopPropagation() ?
- What is ES6? Have you ever used anything from ES6?
- Explain the difference between var, let and const.
- What is the arrow function, and how to create it?
- Give an example of an Arrow function in ES6? List down its advantages.
- Discuss spread operator in ES6 with an example.
- What do you understand about default parameters?
- What are template literals in ES6?
- Tell us the difference between arrow and regular function.
- What’s the difference between map, foreach, filter?
- What’s the difference between filter and find?
- What is the difference between for..of and for..in?
- How do you empty an array?
- Difference between class and object.
- What is a Prototype chain? Or how does inheritance work in JavaScript?
- What does destructing do in es6?
- Is optional chaining is same as ternary operator?
- What do you mean by dot notation and bracket notation? When should you use dot
notation or
bracket notation?
- (এডভান্সড) জাভাস্ক্রিপ্ট এ দুইটা অবজেক্ট সেইম কিনা সেটা কিভাবে কম্পেয়ার করে
- (এডভান্সড) bind, call, apply এর মধ্যে ডিফারেন্স কি
- (এডভান্সড) জাভাস্ক্রিপ্ট এর মধ্যে this কীওয়ার্ড কিভাবে কাজ করে
- arrow ফাংশন আর রেগুলার ফাংশন এর মধ্যে ডিফারেন্স কি
- জাভাস্ক্রিপ্ট কী কী ডাটা টাইপের ভেরিয়েবল আছে?
- জাভাস্ক্রিপ্ট ফাংশন, বা array কি টাইপের জিনিস ?
- জাভাস্ক্রিপ্ট এ array যদি অবজেক্ট হয় তাহলে কিভাবে চেক করবে কোন একটা ভেরিয়েবল একটা array নাকি
array না?
- এর মধ্যে undefined আর null এর মধ্যে ডিফারেন্স কি।
- double equal (==) আর triple equal (===) এই দুইটার মধ্যে ডিফারেন্স কি।
- বা implicit conversion কি জিনিস একটা কখন হয়।
- এছাড়াও জাভাস্ক্রিপ্ট এ কয়েক ধরনের স্কোপ আছে। এই স্কোপ গুলার মধ্যে ডিফারেন্স কি। কখন কোনটা হয়।
- ব্লক স্কোপ কি জিনিস? let, const কি টাইপের স্কোপ তৈরি করে?
- (এডভান্সড) Closure কি জিনিস? এইটা কিভাবে কাজ করে?
- Callback function কি জিনিস?
- (এডভান্সড) Hoisting কি জিনিস? (গুগলে সার্চ দিয়ে আরো ভালো করে শিখো )
- (এডভান্সড) কি ধরণের ভেরিয়েবল reference দিয়ে ফাংশনে পাঠানো হয় আর কোন ধরণের ভেরিয়েবল value
হিসেবে পাঠানো হয়।