Javascript Flashcards

1
Q

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

A

= is called as assignment operator, == is called as comparison operator whereas It is also called as comparison operator. = does not return true or false, == Return true only if the two operands are equal while === returns true only if both values and data types are the same for the two variables.

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

what is higher order function?

A

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
3
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

Undeclared variable is when the variable has not been created.

Undefined variable when the variable is declared, but does not have a value.

a variable is null when the variable is declared, and has a value of nothing, the absence of a value.

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

let, var, const

A

var declarations are globally scoped or function/locally scoped. Old syntax.

Let is block scoped. Can be updated but not re-declared.

Const declarations are block scoped. Cannot be updated or re-declared.

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

What is apply, call and bind?

A

Call is a function that helps you change the context of the invoking function. In layperson’s terms, it helps you replace the value of this inside a function with whatever value you want.

Apply is very similar to the call function. The only difference is that in apply you can pass an array as an argument list.

Bind is a function that helps you create another function that you can execute later with the new context of this that is provided.

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

What is hoisting?

A

Hoisting is a behavior in JavaScript where variable and function declarations are moved to the top of their containing scope during the compilation phase before the code is executed. This means that you can use a variable or call a function before they are declared in the code, and JavaScript will still correctly find and execute them.

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

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

A

asynchronous programming allows certain operations to be performed in the background while the rest of the code continues executing without waiting for those operations to complete.

In JavaScript, asynchronous programming is crucial because JavaScript is a single-threaded language, meaning it executes one task at a time in a specific order. If a task takes a long time to complete, it can block the execution of other tasks, making the application slow and unresponsive.

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

How to compare two objects?

A

_.isEqual()

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

How to copy an Array?

A

Using the Spread Operator (…):
The spread operator allows you to create a shallow copy of an array by expanding its elements into a new array. It creates a new array with the same elements as the original array.

Using the slice() method:
The slice() method returns a shallow copy of a portion of an array specified by its start and end indices. If no arguments are provided, it returns a copy of the entire array.

Using Array.from():
The Array.from() method creates a new array from an iterable object or array-like object. When used with an existing array, it creates a copy of that array.

Using concat() method:
The concat() method is used to merge two or more arrays. When used with a single array, it can be used to create a copy of that array.

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

What is the DOM?

A

Document: The “document” in DOM refers to the HTML document itself. It serves as the entry point for accessing and manipulating the content of the web page.

Object: The DOM represents the HTML elements as objects. Each HTML element is treated as an object, and these objects have properties and methods that developers can use to interact with and modify the elements.

Model: The DOM is a “model” because it provides a structured representation of the HTML document, organizing it into a hierarchical tree structure. Each element, attribute, and text node in the HTML is represented as a node in the DOM tree.

The DOM enables developers to perform various actions on a web page, such as:

Accessing and modifying HTML elements and their attributes.
Adding or removing HTML elements dynamically.
Handling events, such as user interactions (clicks, inputs, etc.).
Animating elements and updating their styles and content in real-time.
Reading and writing data to and from the web page.

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

What is prototypal inheritance?

A

Inheritance: When an object is created, it inherits properties and methods from its prototype. If you access a property or method on the object, and it doesn’t have it, JavaScript will look for that property/method in its prototype, and so on, until it finds it or reaches the Object.prototype.

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

What is cookie? cookies vs localStorage vs sessionStorage?

A

Cookies are mainly used for small data that needs to be sent to the server with each request and can persist across sessions. They have size limitations and are ideal for tasks like user authentication tokens or tracking user activity.

localStorage provides larger storage capacity and persists data across browser sessions. It is suitable for data that needs to be retained across visits, such as user preferences or cached data.

sessionStorage is similar to localStorage but only persists data within a single browser session. It is suitable for temporary data that is needed during the current session and should not be retained beyond that.

Choosing between these storage options depends on the specific use case and requirements of your web application.

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

What’s the benefit of using async/await?

A

The async/await feature in JavaScript provides a more concise and readable way to work with asynchronous code, making it easier to write and understand asynchronous operations. It is built on top of Promises and offers the following benefits:

Readability: async/await allows you to write asynchronous code in a more synchronous style, making it easier to understand and reason about the flow of the program. Asynchronous operations are written using familiar try-catch blocks, which can improve code readability, especially when dealing with multiple asynchronous operations.

Error Handling: With async/await, error handling becomes more straightforward. You can use a try-catch block to catch any errors that occur during asynchronous operations. This helps in avoiding deeply nested Promise chains and simplifies error handling.

Chaining: Instead of chaining multiple .then() methods, async/await allows you to write asynchronous operations sequentially using simple control flow constructs like await. This can make the code more linear and easier to follow.

Debugging: Asynchronous code can be challenging to debug due to the nature of Promise chains. async/await makes debugging easier because the code execution stops at the point of an exception, and you can inspect the variables and state in the try-catch block.

Error Propagation: When using async/await, if an error occurs within the asynchronous function, it automatically rejects the returned Promise, allowing you to handle the error in the catch block. This ensures consistent error propagation through the Promise chain.

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

React context vs Redux

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

How does React use closures?

A

Closures play a vital role in React’s implementation of hooks, such as useState, useEffect, and useCallback.

State Management with useState:
Under the hood, useState uses closures to keep track of the current state value and preserve it across re-renders. The state variables and their update functions are created within the scope of the functional component, and they “remember” their values between different renders.

Event Handling with Closures:
React uses closures to manage event handlers effectively. When you define an event handler inside a functional component, it captures the current state and props at the time of its creation. This ensures that the event handler always has access to the latest state and props, even if they change in subsequent renders.

useEffect and Cleanup Functions:
The useEffect hook is used to perform side effects in functional components. It can also return a cleanup function that will be executed when the component unmounts or before the next effect is executed. The cleanup function also relies on closures to access the state and props at the time the effect was defined.

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

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

A
17
Q

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

A

Setting a key property when mapping over an array in React is important for performance and preventing issues. It helps React efficiently update the DOM when the list changes. The key prop should be unique among siblings. Providing a key helps React keep track of elements, avoid unnecessary reconciliation, and prevent state loss in stateful components. Always use a unique identifier, like an id property from your data, as the key.

18
Q

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

A

Lifting state up is a concept in React where you move the state of a component higher up in the component tree to a common ancestor that can share the state with multiple child components. This is done by passing the state and relevant update functions as props from the parent component to its child components.

We lift state up in React for a few important reasons:

Shared State Management: When multiple components need access to the same state or need to synchronize their state, lifting the state up to a common ancestor allows all the components to share and interact with the same state.

Simpler State Management: By centralizing the state management in a common ancestor, it reduces the complexity and redundancy of handling state updates in different components. This can make the codebase easier to understand and maintain.

Avoiding Prop Drilling:

Easier Testing:

Better Separation of Concerns: Lifting state up promotes better separation of concerns, as components can focus on rendering and behavior while the shared state is managed at a higher level.

Performance Optimization: When state is lifted up, you can optimize the rendering and update behavior of the components by using React’s built-in optimizations, like React.memo or useMemo, effectively improving performance.

19
Q

state vs props

A

State is used for managing component-specific data that can change over time, while props are used for passing data from parent to child components. State is mutable and belongs to a specific component, while props are read-only and allow components to receive data from their parent component.

20
Q

What is the virtual DOM? How does the virtual DOM work?

A

The Virtual DOM is a lightweight and simplified copy of the real DOM used by React. When a component’s state changes, React creates a new Virtual DOM and compares it with the previous one. It identifies the differences (diffing) and updates only the necessary parts of the actual DOM, making the process faster and improving performance. The Virtual DOM helps React efficiently update the user interface without directly manipulating the actual DOM, resulting in a faster and more responsive application.

21
Q

What is JSX?

A

JSX is a special syntax used in React that lets you write HTML-like code inside JavaScript. It makes it easier to create and work with the user interface of React components. JSX gets converted into regular JavaScript to render the components on the web page. It’s a convenient and expressive way to build React UIs.

22
Q

What are the major features of React?

A

Component-Based: React organizes the UI into reusable and independent components, making it easy to build and maintain complex user interfaces.

Virtual DOM: React uses a lightweight Virtual DOM to efficiently update and render components, resulting in faster and more optimized performance.

JSX: React’s JSX syntax allows you to write HTML-like code within JavaScript, making it more readable and intuitive when creating components.

Unidirectional Data Flow: React follows a one-way data flow, where data flows from parent components to child components, making the application easier to understand and debug.

React Hooks: Introduced in React 16.8, hooks enable functional components to use state and lifecycle features, simplifying state management and reusing logic.

23
Q

What is a callback?

A

A callback is a function that gets executed later, after a specific task is done. It’s commonly used in JavaScript for handling asynchronous operations and defining what to do next once a task completes.

24
Q

What is a promise?

A

What is a promise?
A promise is a JavaScript object used for managing asynchronous operations. It represents the result of an operation that may succeed or fail in the future.

25
Q

What is a closure?

A

A closure in JavaScript allows a function to remember and access the variables from its surrounding environment, even after the outer function has finished running. It helps in creating private variables and maintaining references to values outside the function.

26
Q

What is the point of RESTful API?

A

The point of a RESTful API is to provide a standardized way for different software applications to communicate and exchange data over the internet. It allows systems to interact with each other using standard HTTP methods (GET, POST, PUT, DELETE) and follow a set of conventions for organizing and accessing resources, making it easier to build, integrate, and scale web services.

27
Q

What is the difference between REST API and RESTful API?

A

Both terms are often used interchangeably

28
Q

What is Restful API?

A

A RESTful API is a type of web API that follows the principles of Representational State Transfer (REST) architecture. It uses standard HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources and communicates data in a stateless manner. RESTful APIs are designed to be scalable, flexible, and easy to integrate, making them widely used for building web services that can be accessed by different software applications over the internet.

29
Q

What is reponsive design?

A

Responsive design is an approach in web development that makes websites adapt and look good on different devices, like computers, tablets, and phones, by automatically adjusting their layout and content.

30
Q

What is AJAX?

A

AJAX stands for “Asynchronous JavaScript and XML.” It is a web development technique that allows web pages to fetch and send data to a server in the background without needing to reload the entire page. AJAX enables more dynamic and interactive web experiences by updating parts of a webpage without requiring a full refresh, resulting in smoother and faster user interactions.

31
Q

Why do you choose React?

A

State, props, components, JSX, community

32
Q

What is React?

A

Js library. It allows developers to create reusable UI components and efficiently manage the state of a web page. React’s component-based architecture makes it easy to build interactive and responsive user interfaces, enabling the creation of modern, fast, and scalable web applications.

33
Q

How do you send data up from child to parent component

A

To send data from a child component to a parent component in React, you can use a callback function. The parent component passes the callback function as a prop to the child component. Then, the child component can call the callback function and pass the data as an argument, effectively sending the data up to the parent component. This allows the parent component to update its state or perform any other necessary actions based on the data received from the child component.

34
Q

What is an API

A

Application Programming Interface.

A Piece of code you can interact with - exposing some functionality you can use in your code

35
Q

What are 3 main cloud technologies

A

Infrastructure as a service Saas (laas).
Software as a service (Paas)
Platform as a service

36
Q

What are Agile methodologies?

A

Working in sprints.
Have meetings before sprints to go over timelines and tickets.

37
Q

How is the DOM created in vanilla JS vs React?

A

In vanilla JS when the webpage is loaded, the DOM is automatically created.
In React when an element is added to the UI, a virtual DOM is created.