FE interview Flashcards

1
Q

What is React?

A

An open-source JavaScript library developed by Facebook. It’s used for building interactive user interfaces and web applications quickly and efficiently with significantly less code in comparison with vanilla JavaScript.

In React, you develop your applications by creating reusable components that you can treat as independent blocks.

It supports reusable components, cutting down development time.

It uses JSX that makes it easier to code and render elements.

Also it uses Virtual DOM that eliminates excessive re-rendering, ensuring the high performance of your application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Redux?

A

Redux is an open-source JavaScript library for managing and centralizing application state.

It’s required to share data across the application and avoid props drilling.

The main advantage of using Redux is that it provides a predictable way to manage state in the application.

By making all state changes go through a central store, it’s easier to understand how the application’s state is modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are 3 main concepts of Redux?
How does Redux work?

A

Redux has three main concepts:

The store:
This is the single source of truth for the application’s state. It’s a big object that contains the current state of the application, and the central place where all state changes are made.

Actions:
Actions are objects that indicate an intention to change the state of the application. Actions get dispatched to the store. From there, the store uses them to determine how to update its state.

Reducers:
Reducers are pure functions. They take in the current state of the store and an action, and return a new state. They’re responsible for updating the store’s state. They use actions as information to do this. The Redux state should never be modified directly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where is Redux stored

A

Redux keeps the state of the entire application in a single object, called the store. This store is a JavaScript object that provides methods for updating that state. The Redux store is created using the createStore function from the Redux library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What makes Redux so special?

A

The main advantage of using Redux is that it provides a predictable way to manage state in your application.

By making all state changes go through a central store, it’s easier to understand how the application’s state is modified.

Having this single source of truth makes it much easier to debug any issues.

It’s also easier to test, and to reset the store to a known initial state.

When using Redux with React, we can also manage state for React components. This makes it easier to build more complex, interactive applications.

Using Redux also gives a clear way to access and update the state of individual components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Redux set up process

A

Install the Redux library.

Create a store using the createStore function from the Redux library. We will pass the store a reducer function. This is a pure function that takes in the current state of the store and an action, and returns a new state.

Dispatch actions to the store using the dispatch method and passing it an action object. The store will use the reducer function to update its state based on the action that was dispatched.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why do you choose React?

A

React allows developers to utilize individual parts of their application, which boosts the speed of the development process. In simple terms, different developers can write individual parts and these changes will not cause the logic of the application.

It makes JavaScript coding more simple

It supports reusable components, cutting down development time.

JSX makes it easier to code and render elements.

Virtual DOM eliminates excessive re-rendering, ensuring the high performance of your application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is AJAX?

A

AJAX = Asynchronous JavaScript And XML.
AJAX is not a programming language.
AJAX just uses a combination of: A browser built-in XMLHttpRequest object (to request data from a web server)

AJAX is an acronym for Asynchronous JavaScript and XML. It is a group of inter-related technologies like JavaScript, DOM, XML, HTML/XHTML, CSS, XMLHttpRequest etc.

AJAX allows to send and receive data asynchronously without reloading the web page. So it is fast.

AJAX allows to send only important information to the server not the entire page. So only valuable data from the client side is routed to the server side. It makes the application interactive and faster.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is responsive design?

A

Responsive Web Design is about using HTML and CSS to automatically resize, hide, shrink, or enlarge, a website, to make it look good on all devices (desktops, tablets, and phones)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Restful API?

A

RESTful API is an interface that two computer systems use to exchange information securely over the internet.

REST API is nothing but an application programming interface that follows REST architectural constraints such as statelessness, cacheability, maintainability, and scalability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between REST API and RESTful API?

A

The REST API follows all the rules of the REST Architecture. It has a client-server, stateless, cacheable, layer system with a uniform interface, whereas the RESTful web applications have all the features of the REST architecture with unique additional features

REST (REpresentational State Transfer) is basically an architectural style of development having some principles:

It should be stateless

It should access all the resources from the server using only URI

It does not have inbuilt encryption

It does not have session

It uses one and only one protocol - HTTP

For performing CRUD operations, it should use HTTP verbs such as get, post, put and delete

It should return the result only in the form of JSON or XML, atom, OData etc. (lightweight data )

REST based services follow some of the above principles and not all

RESTFUL services means it follows all the above principles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the point of RESTful API?

A

RESTful APIs are the most commonly used APIs in the world of web services. They use Hypertext Transfer Protocol (HTTP) requests to create, read, update, and delete (CRUD) data. They are popular because of their simplicity, scalability, speed, and ability to handle all data types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a promise?

A

Promises are used to handle asynchronous operations in javascript

Before promises, callbacks were used to handle asynchronous operations. But due to the limited functionality of callbacks, using multiple callbacks to handle asynchronous code can lead to unmanageable code.

Promise object has four states -

Pending - Initial state of promise. This state represents that the promise has neither been fulfilled nor been rejected, it is in the pending state.

Fulfilled - This state represents that the promise has been fulfilled, meaning the async operation is completed.

Rejected - This state represents that the promise has been rejected for some reason, meaning the async operation has failed.

Settled - This state represents that the promise has been either rejected or fulfilled. A promise is created using the Promise constructor which takes in a callback function with two parameters, resolve and reject respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a callback?

A

Callbacks are functions that can be passed as an argument to another function. The callback function can be called from the function to which it was passed after some event has happened. Usually used for asynchronous actions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the major features of React?

A

JSX.
Components.
One-way Data Binding.
Virtual DOM.
Simplicity.
Performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is JSX?

A

JSX stands for JavaScript syntax extension. It is a JavaScript extension that allows us to describe React’s object tree using a syntax that resembles that of an HTML template. It is just an XML-like extension that allows us to write JavaScript that looks like markup and have it returned from a component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the virtual DOM

A

a concept used in react to provide faster updates on the DOM, React keeps in memory a copy of DOM, whenever there is an update React updates virtual DOM and sync it with real DOM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How does the virtual DOM work?

A

The virtual DOM is only a virtual representation of the DOM. Every time the state of our application changes, the virtual DOM gets updated instead of the real DOM.

React uses Virtual DOM which is like a lightweight copy of the actual DOM (a virtual representation of the DOM). So for every object that exists in the original DOM, there is an object for that in React Virtual DOM. It is exactly the same, but it does not have the power to directly change the layout of the document. Manipulating DOM is slow, but manipulating Virtual DOM is fast as nothing gets drawn on the screen. So each time there is a change in the state of our application, the virtual DOM gets updated first instead of the real DOM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does lifting state up mean and why do we do it?

A

In React, sharing state is accomplished by moving it up to the closest common ancestor of the components that need it. This is called “lifting state up”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Why do we set a key property when we map over an array in React?

A

Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.

React uses the key prop to understand the component-to-DOM Element relation, which is then used for the reconciliation process.

Unique keys allow React not mix up the elements and avoid to mutate incorrect elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the core principles of Redux?

A

Single source of truth​ The global state of your application is stored in an object tree within a single store.

State is read-only​ The only way to change the state is to emit an action, an object describing what happened.

Changes are made with pure functions​

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do I make an AJAX request using Redux?

A

In old redux we apply redux-thunk middleware which allows you to define async actions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the benefits of using Redux DevTools?

A

Redux DevTool allows us to dispatch actions without writing any code. We can add our actions in dispatcher and it works just like action dispatched via Redux API. This kind of mocking helps in testing side effects and dependent actions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do I use React DevTools? What does this help me with?

A

It enables developers to debug their code inside their Developer Tools.

We can check the props/ state/ hooks of the component

We can edit the props/ state from dev tools

We can search for a component

We can check the component’s tree

We can log a component’s data in the console

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Closure

A

Closures are inner functions that have access to the outer function’s variables and parameters. Even after the outer function’s execution is finished, the inner functions have access to the variables in the outer function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is redux-thunk?

A

“thunks” are a pattern of writing functions with logic inside that can interact with a Redux store’s dispatch and getState methods. Using thunks requires the redux-thunk middleware to be added to the Redux store as part of its configuration.

Redux Thunk is middleware that allows you to return functions, rather than just actions, within Redux. This allows for delayed actions, including working with promises

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

React context vs Redux

A

The main difference between these two libraries is that Redux deals with changes of the state in a centralized manner. On the other hand, Context deals with them as they happen on the component level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What’s the benefit of using async/await?

A

Code is easily readable
Use numerous async functions in a row
Simpler debugging process
More convenient way of error handling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is cookie?
Cookies vs localStorage vs sessionStorage?

A

Cookies - the simplest form of browser storage.
Key-Value pairs.
Often set by the server - logging info.
Can also be created via document.cookie.

Local storage - part of the web storage API.
System for storing information in the browser.
No expiration date.

Session storage - the same.
Expires at. the end of a session.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is prototypal inheritance?

A

All javascript objects inherit properties from a prototype.
For example,
Array objects inherit properties from the Array prototype.

On top of the chain is Object.prototype. Every prototype inherits properties and methods from the Object.prototype.

A prototype is a blueprint of an object. The prototype allows us to use properties and methods on an object even if the properties and methods do not exist on the current object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is the DOM?

A

DOM stands for Document Object Model.
DOM is a programming interface for HTML and XML documents.
When the browser tries to render an HTML document, it creates an object based on the HTML document called DOM.
Using this DOM, we can manipulate or change various elements inside the HTML document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

How to compare two objects?

A

Objects are reference types so you can’t just use === or == to compare 2 objects. One quick way to compare if 2 objects have the same key value, is using JSON.stringify. Another way is using Lodash isEqual function 👏

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is asynchronous programming and why is it important in JavaScript?

A

Asynchronous programming is a technique that enables your program to start a potentially long-running task and still be able to be responsive to other events while that task runs, rather than having to wait until that task has finished

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is hoisting?

A

Hoisting is the default behavior of javascript where all variables with var keyword and function declarations are moved on top of the scope. The scope can be both local and global.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is apply, call and bind?

A

call()
It’s a predefined method in javascript
allows an object to use the method of another object.
accepts arguments

apply()
is similar to the call() method. The only difference is that, call() method takes arguments separately whereas, apply() method takes arguments as an array

bind()
returns a new function, where the value of “this” keyword will be bound to the owner object, which is provided as a parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?

A

null is actual value
undefined - when a variable in declared but not initialized.
use the typeof operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

what is higher order function?

A

What is a Higher Order Function? A higher order function is a function that takes one or more functions as arguments, or returns a function as its result. There are several different types of higher order functions like map and reduce.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is the difference between == and ===?

A

Both are comparison operators. The difference between both the operators is that “==” is used to compare values whereas, “ === “ is used to compare both values and types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is the difference between store and reducer

A

Store - Is what holds all the data your application uses. Reducer - is what manipulates that data when it recieves an action. Action - is what tells reducer to manipulate the store data, it carries the name and (not required) some data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

How do you send data up from child to parent component

A

Pass a function as a prop to the Child component.
Call the function in the Child component and pass the data as arguments.
Access the data in the function in the Parent .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

How browser works

A
  1. When you visit a website, the web browser that you are using will contact the DNS server that will translate the human readable website name into a numeric IP address. Every website name is basically an alias for an IP address. So, DNS converts that URL into IP address, and each website has its own unique IP address.
    Once a DNS server finds the IP address of the website, that IP address will be returned to the browser.
  2. The browser will use the IP address to communicate with the web server.
  3. Now that your browser has a connection with the website’s web server, your browser will retrieve the html code of the specific page that is requested.
  4. Once your browser receives the HTML code from the web server, it will display that HTML code to you in the browser window.
  5. If and when you close that particular browser window, the connection with the web server will end.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

How does HTTP work?

A

HTTP stands for Hypertext Transfer Protocol. It is a set of rules which is used for transferring the files like, audio, video, mage, text and other files. HTTP is a protocol that is used to transfer the hypertext from the client end to the server end, but HTTP does not have any security. Whenever a user opens their Web Browser, that means the user indirectly uses HTTP.

HTTP Requests are messages which are sent by the client or user to initiate an action on the server.

It has Request Header Fields: The request-header fields are used to allow the client to pass additional information to the server like the request and the client itself. The request header fields act as request modifiers, with semantics equivalent to the parameters on a programming language method invocation.

It has methods: get, post, patch, delete

The Server issues an HTTP Status Code in response to a request of the client made to the server. Status code is a 3-digit integer. The first digit of status code is used to specify one of five standard classes of responses. The last two digits of status code do not have any categorization role.

URI stands for uniform resource identifier. URIs define the identity of anything, including information resources such as web pages available on the internet and distinguish one resource from another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Virtual DOM

A

a concept used in react to provide faster updates on the DOM, React keeps in memory a copy of DOM, whenever there is an update React updates virtual DOM and sync it with real DOM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

State

A

JS variable, whenever its value is updated it triggers a rerender the application and a new value is displayed in the UI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Rules when using hooks in React

A

hooks should not be called inside of functions, loops, if statements.
It should be called inside the component but above functions loops.
only in functional components

46
Q

What is a pure function?

A

A Pure Function is a function that always returns the same result if the same arguments are passed. It does not depend on any state or data change during a program’s execution. Rather, it only depends on its input arguments.

A pure function is a function that satisfies the following two conditions:
Given the same input, it always returns the same output.
Causes no side effects outside the function’s scope.

The side-effect is a function that modifies any data outside of its scope.

47
Q

What are hooks?

A

Hooks are a new feature added in React v16.8. It allows to use all React features without writing class components.
These are in-built functions that allow developers to use state and lifecycle methods within components in React

48
Q

UseRef

A

To get access to underlying DOM element

49
Q

What is a callback hell?

A

Callbacks are functions that can be passed as an argument to another function. The callback function can be called from the function to which it was passed (caller) after some event has happened. Used for asynchronous actions

50
Q

Features of JavaScript

A

It is a lightweight, interpreted programming language - does not require compilation. It can be added to HTML and when the page loads, scripts execute automatically
Executed inside user’s browsers
Event-driven: respond to events
Limitation: executes in a single thread. Browsers uses event loop to mimic concurrency
It was created with the intention to be used in browsers, and now it is also used on server side
After HTML and CSS, JS is the third biggest web technology
Supports OOP
It is an open and cross-platform language

51
Q

Is JavaScript a case-sensitive language?

A

Yes, JavaScript is a case sensitive language. The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

52
Q

Advantages of using JavaScript

A
  1. Javascript is executed on the client-side as well as server-side also. There are a variety of Frontend Frameworks that you may study and utilize. However, if you want to use JavaScript on the backend, you’ll need to learn NodeJS. It is currently the only JavaScript framework that may be used on the backend.
  2. Javascript is a simple language to learn.
  3. Web pages now have more functionality because of Javascript.
  4. To the end-user, Javascript is quite quick
53
Q

String

A

It represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.

54
Q

Number

A

It represents a number and can be written with or without decimals

55
Q

BigInt

A

This data type is used to store numbers which are above the limitation of the Number data type. It can store large integers and is represented by adding “n” to an integer literal

56
Q

Boolean

A

It represents a logical entity and can have only two values : true or false. Booleans are generally used for conditional testing

57
Q

Undefined

A

When a variable is declared but not assigned, it has the value of undefined and it’s type is also undefined

58
Q

Null

A

It represents a non-existent or a invalid value

59
Q

Symbol

A

It is a new data type introduced in the ES6 version of javascript. It is used to store an anonymous and unique value

60
Q

Scopes of a variable in JavaScript?

A

The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.
* Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code.
* Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

61
Q

What is the purpose of ‘This’ operator in JavaScript?

A

The JavaScript this keyword refers to the object it belongs to. This has different values depending on where it is used. In a method, this refers to the owner object and in a function, this refers to the global object.

n call(), apply() and, bind() methods

62
Q

Types of errors

A
  1. Syntax error: Syntax errors are mistakes or spelling problems in the code that cause the program to not execute at all or to stop running halfway through. Error messages are usually supplied as well.
  2. Logical error: Reasoning mistakes occur when the syntax is proper but the logic or program is incorrect. The application executes without problems in this case. However, the output findings are inaccurate. These are sometimes more difficult to correct than syntax issues since these applications do not display error signals for logic faults
63
Q

Memoization

A

Memoization is a form of caching where the return value of a function is cached based on its parameters. If the parameter of that function is not changed, the cached version of the function is returned

64
Q

Advantages of using External JavaScript

A
  1. It allows web designers and developers to collaborate on HTML and javascript files.
  2. We can reuse the code.
  3. Code readability is simple in external javascript
65
Q

Currying

A

Currying is an advanced technique to transform a function with several arguments, to several functions with one or fewer arguments

66
Q

The variable naming conventions in JavaScript?

A

You should not use any of the JavaScript reserved keyword as variable name. For example, break or boolean variable names are not valid.
JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or the underscore character. For example, 123name is an invalid variable name but _123name or name123 is a valid one.
JavaScript variable names are case sensitive. For example, Test and test are two different variables.

67
Q

What is the difference between Attributes and Property?

A

Attributes - provide more details on an element like id, type, value etc.
Property - is the value assigned to the property like type=”text”, value=’Name’ etc.

68
Q

What is a Typed language?

A

Typed Language is in which the values are associated with values and not with variables. It is of two types:
Dynamically: in this, the variable can hold multiple types; like in JS a variable can take numbers, chars.
Statically: in this, the variable can hold only one type, like in Java a variable declared of string can take only a set of characters and nothing else.

69
Q

Recursion

A

Recursion is a technique to iterate over an operation by having a function call itself repeatedly until it arrives at a result

70
Q

Constructor function

A

Constructor functions are used to create objects in javascript when we want to create multiple objects having similar properties and methods, constructor functions are used.

71
Q

BOM

A

Browser Object Model is known as BOM. It allows users to interact with the browser. A browser’s initial object is a window. As a result, you may call all of the window’s functions directly or by referencing the window. The document, history, screen, navigator, location, and other attributes are available in the window object.

72
Q

Differences between declaring variables using var, let and const

A

The variables declared with the let keyword in the global scope behave just like the variable declared with the var keyword in the global scope.
Variables declared in the global scope with var and let keywords can be accessed from anywhere in the code.
But, there is one difference! Variables that are declared with the var keyword in the global scope are added to the window/global object. Therefore, they can be accessed using window.variableName.
Whereas, the variables declared with the let keyword are not added to the global object, therefore, trying to access such variables using window.variableName results in an error
Variables are declared in a functional/local scope using var and let keywords behave exactly the same, meaning, they cannot be accessed from outside of the scope
In javascript, a block means the code written inside the curly braces {}.
Variables declared with var keyword do not have block scope. It means a variable declared in block scope {} with the var keyword is the same as declaring the variable in the global scope.
Variables declared with let keyword inside the block scope cannot be accessed from outside of the block

73
Q

Rest parameter and spread operator

A

Both rest parameter and spread operator were introduced in the ES6 version of javascript.
Rest parameter ( … ):
It provides an improved way of handling the parameters of a function.
Using the rest parameter syntax, we can create functions that can take a variable number of arguments.
Any number of arguments will be converted into an array using the rest parameter.
It also helps in extracting all or some parts of the arguments.
Rest parameters can be used by applying three dots (…) before the parameters
Spread operator (…):
Although the syntax of the spread operator is exactly the same as the rest parameter, the spread operator is used to spreading an array, and object literals. We also use spread operators where one or more arguments are expected in a function call

74
Q

Generator

A

Introduced in the ES6 version, generator functions are a special class of functions. They can be stopped midway and then continue from where they had stopped. Generator functions are declared with the function* keyword instead of the normal function keyword
In normal functions, we use the return keyword to return a value and as soon as the return statement gets executed, the function execution stops
In the case of generator functions, when called, they do not execute the code, instead, they return a generator object
The generator object consists of a method called next(), this method when called, executes the code until the nearest yield statement, and returns the yield value
As one can see the next method returns an object consisting of a value and done properties. Value property represents the yielded value. Done property tells us whether the function code is finished or not. (Returns true if finished)

75
Q

Classes

A

Introduced in the ES6 version, classes are nothing but syntactic sugars for constructor functions. They provide a new way of declaring constructor functions in javascript.
Key points to remember about classes:
Unlike functions, classes are not hoisted.
A class cannot be used before it is declared. A class can inherit properties and methods from other classes by using the extend keyword.
All the syntaxes inside the class must follow the strict mode(‘use strict’) of javascript. An error will be thrown if the strict mode rules are not followed

76
Q

Set

A

is a collection of unique and ordered elements

77
Q

WeakSet

A

Set is a collection of unique and ordered elements.
Just like Set, WeakSet is also a collection of unique and ordered elements with some key differences:
Weakset contains only objects and no other type.
An object inside the weakset is referenced weakly. This means, that if the object inside the weakset does not have a reference, it will be garbage collected.
Unlike Set, WeakSet only has three methods, add() , delete() and has()

78
Q

WeakMap

A

Map is used to store key-value pairs. The key-value pairs can be of both primitive and non-primitive types.
WeakMap is similar to Map with key differences:
The keys and values in weakmap should always be an object.
If there are no references to the object, the object will be garbage collected

79
Q

Object Destructuring

A

Object destructuring is a new way to extract elements from an object or an array
To extract all the elements inside an object in one line of code

80
Q

Temporal Dead Zone

A

Temporal Dead Zone is a behavior that occurs with variables declared using let and const keywords. It is a behavior where we try to access a variable before it is initialized

81
Q

Arrow functions

A

Arrow functions were introduced in the ES6 version of javascript. They provide us with a new and shorter syntax for declaring functions. Arrow functions can only be used as a function expression
Arrow functions are declared without the function keyword. If there is only one returning expression then we don’t need to use the return keyword as well in an arrow function as shown in the example above. Also, for functions having just one line of code, curly braces { } can be omitted
If the function takes in only one argument, then the parenthesis () around the parameter can be omitted
In the arrow functions, there is no binding of this keyword. This keyword inside an arrow function does not refer to the object calling it. It rather inherits its value from the parent scope

82
Q

What is the difference between Local storage & Session storage?

A

Local Storage – The data is not sent back to the server for every HTTP request (HTML, images, JavaScript, CSS, etc) – reducing the amount of traffic between client and server. It will stay until it is manually cleared through settings or program.
Session Storage – It is similar to local storage; the only difference is while data stored in local storage has no expiration time, data stored in session storage gets cleared when the page session ends. Session Storage will leave when the browser is closed.
In case you are facing any challenges with these JavaScript Interview Questions, please comment on your problems in the section below.

83
Q

What is the difference between null & undefined?

A

Undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.

84
Q

What is the difference between undeclared & undefined?

A

Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered. Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.

85
Q

Deferred scripts

A

The processing of HTML code while the page loads are disabled by nature till the script hasn’t halted. Your page will be affected if your network is a bit slow, or if the script is very hey. When you use Deferred, the script waits for the HTML parser to finish before executing it. This reduces the time it takes for web pages to load, allowing them to appear more quickly

86
Q

What is the difference between window & document in JavaScript?

A

JavaScript window is a global object which holds variables, functions, history, location.

The document also comes under the window and can be considered as the property of the window.

87
Q

What is the difference between innerHTML & innerText?

A

innerHTML – It will process an HTML tag if found in a string
innerText – It will not process an HTML tag if found in a string

88
Q

What is an event bubbling in JavaScript?

A

Event bubbling is a way of event propagation in the HTML DOM API, when an event occurs in an element inside another element, and both elements have registered a handle for that event. With bubbling, the event is first captured and handled by the innermost element and then propagated to outer elements. The execution starts from that event and goes to its parent element. Then the execution passes to its parent element and so on till the body element.

89
Q

What is NaN in JavaScript?

A

NaN is a short form of Not a Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number. When a string or something else is being converted into a number and that cannot be done, then we get to see NaN.
In case you are facing any challenges with these JavaScript Interview Questions, please comment on your problems in the section below.

90
Q

How do JavaScript primitive/object types passed in functions?

A

One of the differences between the two is that Primitive Data Types are passed By Value and Objects are passed By Reference.
By Value means creating a COPY of the original. Picture it like twins: they are born exactly the same, but the first twin doesn’t lose a leg when the second twin loses his in the war.
By Reference means creating an ALIAS to the original. When your Mom calls you “Pumpkin Pie” although your name is Margaret, this doesn’t suddenly give birth to a clone of yourself: you are still one, but you can be called by these two very different names.

91
Q

How can you convert the string of any base to integer in JavaScript?

A

The parseInt() function is used to convert numbers between different bases. It takes the string to be converted as its first parameter, and the second parameter is the base of the given string.

92
Q

What are Exports & Imports?

A

Imports and exports help us to write modular JavaScript code. Using Imports and exports we can split our code into multiple files.

93
Q

What is the ‘Strict’ mode in JavaScript and how can it be enabled?

A

Strict mode is a way to introduce better error-checking into your code.
When you use strict mode, you cannot use implicitly declared variables, or assign a value to a read-only property, or add a property to an object that is not extensible.
You can enable strict mode by adding “use strict” at the beginning of a file, a program, or a function.

94
Q

Git

A

A version control system is a system that keeps track of all changes made to a file so that a specific version can be reverted if necessary
this ensures that everyone in the team is working on the most recent version of the file

Git push is used to push the local repository content to a remote repository
After a local repository has been modified a push is executed to share the modification with remote team members

95
Q

Scope

A

Global Scope
Variables or functions declared in the global namespace have global scope, which means all the variables and functions having global scope can be accessed from anywhere inside the code

Function Scope
Any variables or functions declared inside a function have local/function scope, which means that all the variables and functions declared inside a function, can be accessed from within the function and not outside of it

Block Scope
Block scope is related to the variables declared using let and const. Variables declared with var do not have block scope. Block scope tells us that any variable declared inside a block { }, can be accessed only inside that block and cannot be accessed outside of it.

96
Q

Event Delegation

A

providing event listener to parent and access the child element with the help of this event

97
Q

Debugger

A

The debugger for the browser must be activated in order to debug the code. Built-in debuggers may be switched on and off. The remaining section of the code should stop execution before moving on to the next line while debugging

98
Q

Difference between ‘var’ and ‘let’ keywords

A

var is in JS since the beginning
var has function scope - it does not respect other blocks
var gets hoisted to top of scope - namely its definition is hoisted, not value

let was introduced in ES6
let has block scope - available only within block

99
Q

Difference between null and undefined

A

null is actual value
undefined - when a variable is declared but not initialized

100
Q

Implicit Type Coercion

A

Implicit type coercion in javascript is the automatic conversion of value from one data type to another. It takes place when the operands of an expression are of different data types

String coercion
String coercion takes place when using ‘ + ‘ operator. When a number is added to a string, the number type is always converted to the string type

while using ‘ - ‘ operator is that, a string is converted to a number and then subtraction takes place

Boolean Coercion
Boolean coercion takes place when using logical operators, ternary operators, if statements, and loop checks. To understand boolean coercion in if statements and operators, we need to understand truthy and falsy values
All values except false, 0, 0n, -0, “”, null, undefined, and NaN are truthy values

Equality Coercion
Equality coercion takes place when using ‘ == ‘ operator
The ‘==’ operator, converts both the operands to the same type and then compares them

101
Q

Logical operators

A

Logical operators in javascript, unlike operators in other programming languages, do not return true or false. They always return one of the operands.
OR ( | | ) operator - If the first value is truthy, then the first value is returned. Otherwise, always the second value gets returned.
AND ( && ) operator - If both the values are truthy, always the second value is returned. If the first value is falsy then the first value is returned or if the second value is falsy then the second value is returned

102
Q

JS is dynamically typed language

A

JavaScript is a dynamically typed language. In a dynamically typed language, the type of a variable is checked during run-time in contrast to a statically typed language, where the type of a variable is checked during compile-time

103
Q

What is NaN property

A

NaN property represents the “Not-a-Number” value. It indicates a value that is not a legal number. typeof of NaN will return a Number. To check if a value is NaN, we use the isNaN() function
isNaN() function converts the given value to a Number type, and then equates to NaN

104
Q

Immediately Invoked Function

A

An Immediately Invoked Function ( known as IIFE and pronounced as IIFY) is a function that runs as soon as it is defined
To understand IIFE, we need to understand the two sets of parentheses that are added while creating an IIFE
W add the first set of parenthesis that tells the compiler that the function is not a function declaration, instead, it’s a function expression
The second set of parenthesis invokes the function

105
Q

Strict mode

A
  1. Duplicate arguments are not allowed by developers.
  2. In strict mode, you won’t be able to use the JavaScript keyword as a parameter or function name.
  3. The ‘use strict’ keyword is used to define strict mode at the start of the script. Strict mode is supported by all browsers.
  4. Engineers will not be allowed to create global variables in ‘Strict Mode
106
Q

Higher Order Functions

A

Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions

107
Q

Prototypes

A

All javascript objects inherit properties from a prototype. For example,
Date objects inherit properties from the Date prototype
Math objects inherit properties from the Math prototype
Array objects inherit properties from the Array prototype.
On top of the chain is Object.prototype. Every prototype inherits properties and methods from the Object.prototype. A prototype is a blueprint of an object. The prototype allows us to use properties and methods on an object even if the properties and methods do not exist on the current object

108
Q

SOLID

A

Helps to write better code
Avoid duplicate code
Easy to maintain
Easy to understand
Flexible software
Reduce complexity

Single Responsibility Principle
A Class should have one and one reason to change

Open/Closed Principle
Software entities should be open for extension but closed for modification

Liskov substitution principle
Subtypes must be substitutable for their base types

Interface Segregation Principle
Keep the interfaces as small as possible.
The dependency of class to another one should depend on the smallest possible interface

Dependency Inversion Principle
Depend upon abstractions (interfaces) not upon concrete classes

109
Q

JavaScript

A

The primary programming language of the web, primarily used for adding functionality to websites. JavaScript is a general purpose multi-paradigm programming language with dynamic typing. Learn more: https://developer.mozilla.org/en-US/docs/Web/JavaScript Paradigm A style of programming. Oftentimes languages are built with a specific paradigm in mind, but JavaScript is known as a multi-paradigm language, because it allows for programming in a variety of paradigms. Some of the major paradigms of JavaScript include:

Event-driven: Functions can be made to respond to events, such as when a user clicks on an element or scrolls down the page.

Functional: Functions can be written as “pure functions”, meaning functions that always have the same output for a given set of arguments and never produce side effects. Additionally, JavaScript supports first-class functions and higher-order functions. This means that functions can be treated as normal values, passed as arguments to other functions and returned from functions.

Object-oriented: Objects can be created as custom data stores and they can be made to inherit from each other.

Imperative: Programs can be written by explicitly describing the control flow, such as with loops and conditionals.

Declarative: Programs can be written by describing the desired output with implicit control flow. Oftentimes this is associated with functional programming (e.g. using the forEach function to loop over an array instead of a for loop).

110
Q

React

A

A JavaScript library developed by Facebook for building user interfaces. React uses a component-based architecture to create interfaces with an intuitive declarative approach.

Component : A reusable independent piece of a user interface. In modern React, components are usually functional components, which are simply functions that return JSX.

JSX : Short for JavaScript XML, a JavaScript syntax extension for inlining XML and HTML in JavaScript.

ReactDOM : A package used with React to work as the bridge between React elements and the actual DOM in the browser. The most frequently used ReactDOM function is the render function, which adds a component to the DOM.