0% found this document useful (0 votes)
19 views5 pages

JavaScript and React Interview Questions

The document covers various JavaScript concepts, including primitive and non-primitive data types, string manipulation using regular expressions, random song selection from an array, and recursive functions. It also discusses React features like Virtual DOM, code splitting, and the differences between React versions, along with Redux principles and usage. Additionally, it touches on CSS selectors, semantic HTML elements, and the importance of CI/CD pipelines in software development.

Uploaded by

Pavan Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

JavaScript and React Interview Questions

The document covers various JavaScript concepts, including primitive and non-primitive data types, string manipulation using regular expressions, random song selection from an array, and recursive functions. It also discusses React features like Virtual DOM, code splitting, and the differences between React versions, along with Redux principles and usage. Additionally, it touches on CSS selectors, semantic HTML elements, and the importance of CI/CD pipelines in software development.

Uploaded by

Pavan Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

javascript:

----------------------------------------------------------------
1. What are non primitive data types and primitve data types
Ans: Non-primitive: array, object, functions
Primitive : string, number, null, undefined, boolean
2. how do you extract only alphabets from the below string using regular expresion
or tell him his wish?
var str = "Wel34#%*com5e" // Welcome
Ans: [Link](/[^a-zA-Z]/gi, '') or diff solutions
3. using below data how do you play random song from below array list?
var data = ["song1.mp3", "song2.mp3", "song3.mp3", "song4.mp3", "song5.mp3"]
Ans: data[[Link]([Link]() * [Link])]
4. how to increment and decrement a value. open below link write a program with out
using
any global variable (give below link to candidate)
[Link]
[Link]
5. reverse string with out using any predefined methods like split reverse join-
using prototype develop program
Ans: [Link] = function() {
var str = "";
for(var i=[Link]-1; i>=0 ; i--) {
str += this[i]
}
return str;
}
//"govind".rev() // dnivog

6. What is recursive function and using recurisve strategy how do you add one or
more disabled parameter to the below data
(if you want create in react js also)
var data = [
{
name: "General",
children: [
{
name: "Account",
children: []
}
]
},
{
name: "Category",
children: [
{
name: "Subject",
children: []
}
]
}
]
output:
var outputdata = [
{
name: "General",
disabled: false,
children: [
{
name: "Account",
disabled: false,
children: []
}
]
},
{
name: "Category",
disabled: false,
children: [
{
name: "Subject",
disabled: false,
children: []
}
]
}
]
Ans:
function recursive(data) {
return [Link](x=> {
return ({
...x,
disabled: false,
children: [Link] ? recursive([Link]) : []
})
})
}
OR diff solution using for loop ...etc
7. How to detect user in online or ofline using javascript

var data - [""]


React JS
------------------------------------------------------
What is Virtual DOM?
Virtual DOM is technique to optimize the performance of an application, basically
it compares two render trees to know what exactly changed
and only updates what is necessary on the actual DOM In React, for every DOM
object, there is a corresponding “virtual DOM object.”
A virtual DOM object is a representation of a DOM object

1. what is current version of react js including version number


2. Difference between react 18 and 17
3. What is React DOM Client (introduced in react 18)
4 -in react 18 what methods replaced by [Link] and [Link]
OR What are new root api's in react 18
Ans: createRoot and hydrateRoot
5. what is code splitting
Ans: [Link]() and [Link]() using this we can reduce the inital
loading bundle size that mean it load component based on demand
6. diff between useMemo and useCallback and write syntax diference
Ans:
const table = useMemo(() => (<TableComponent data={list} />), [list])// it
will re-render only when there is change in data list
const handleChange = useCallback(()=> {
//your code here
});
7. Open Note pad and write a reusable collapsible accordion component in reactjs
(if candiate reaches min 70% code then consider)
var data = [
{
name: "General",
content: "General text goes here"
},
{
name: "Category",
content: "text goes here"
}
]
8. create custom hook in react js
9. what is render props feature in react js
10. What are the usage of interceptors

Redux:
---------------------------------------
1. What are the Redux Three Principles
- Single source of truth ([Link]())
- state is readonly (dispatch) - The only way to change the state is to emit an
action using dispatch,
- changes happen through pure functions (reducers)
2. what is usage of batch method in redux
Ans: for grouping multiple dispatch events to improve performance
3. how to handle api call using
Ans: dispatch(action1)
const action1 =() {
return (dipatch) => {
[Link](url).then((res)=> {
dispatch({type: "actionname", payload: res})
})
}
}
4. diff between redux and redux toolkit

CSS:
---------------------------
1. What are the available combinators (important selectors)
Ans:
descendant selector (space)
child selector (>)
adjacent sibling selector (+)
general sibling selector (~)
2. css browser prefixes
Ans: -webkit-, -moz-, -ms-, -o-
3. diff between flex-shrink and flex-basis

HTML:
-What are the semantic and non-semantic elements
Ans: Semantic: article, main, section, header, footer, nav ...etc
Non-semantic:div, span
-What are available new form control elements
-What are the availble web storages
Ans: local storage and session storage
-what is diff between session and local storages

[Link]
native/
4 and below
JS
---------------
-What is implicity type conversion and explicity type conversion
Ans: implicity is done by javascript like alert(8.2); cancatenaton, substraction
tow strings, modululo(%)
Explicity is done by using inbuilt methods like toString, Number, parseInt,
String ..etc
-data types
-increment and decrement program
-string methods
-remove duplicates array using for loop
-array strings random value print
-string reverse with out prdefined methods
-self invoking function
-diff between for IN and for OF
-how to iterate object
-how to

UI Developer What you do: • Demonstrate development skills in front-end development


of application using Angular 8+.
• Experience in working with frameworks like REDUX. • Proficient in writing and
executing unit test cases using Karma and Jasmine. •
Use UI best practices and design patterns such as MVC, MVVM to build highly
scalable solutions.
• Experience in developing Headless architecture based UI applications.
• Build solutions for UI modernization and Migrations of Large Scale Application
Portfolios including patterns and approaches for move to cloud.
• Integrate Identity management and modern authentication and authorization
protocols such as OIDC, OAuth 2.0.
• Integrate with Serverless Functions, Logic Apps for event driven processes and
integrations
• Integrate CI/CD and continuous testing practices with ESLint into the engineering
lifecycle.
• Proficiency in working with tools for agile delivery like JIRA.
• Proficient in writing and executing unit test cases using Karma and Jasmine.
Skills you have: Must Have Should have knowledge of Angular 8+, HTML5, CSS3,
JavaScript,
jQuery, Bootstrap Must Have Should have knowledge of Typescript & ES (latest
version)
Must Have Familiarity with Popular JavaScript Libraries such as React and REDUX
Must Have
Should be able to debug on Developer Tools of the browser and Working with Cross
Browser UI
Must Have Should have good understanding in Agile Software Development projects
Preferred Good understanding and experience with Object-Oriented concepts
Preferred Knowledge of unit testing tools such as Zest, Enzyme etc.
Preferred Knowledge of Angular 8+, HTML5, CSS3, JavaScript, jQuery,
Bootstrap, Material Design Preferred Knowledge of Typescript & ES6 and ES7

function pnt(n) {
for(var row=1; row<=n; row++) {
for(var col=1; col<=row; col++) {
[Link]("* ")
}
[Link]("")
}
}
event-listner-dmk95p

function isEmptyInputValue(value: any): boolean {


// we don't check for string here so it also works with arrays
return value == null || [Link] === 0;
}

CICD pipe line:

A continuous integration and continuous deployment (CI/CD) pipeline


is a series of steps that must be performed in order to deliver
a new version of software. CI/CD pipelines are a practice focused on improving
software delivery
throughout the software development life cycle via automation.

By automating CI/CD throughout development, testing, production,


and monitoring phases of the software development lifecycle,
organizations are able to develop higher quality code, faster.
Although it’s possible to manually execute each of the steps of a CI/CD pipeline,
the true value of CI/CD pipelines is realized through automation.

const mockAxios = axios as [Link]<typeof axios>

Custom hook
const useBoolean = () => {
const [state, setState] = [Link]();

const handleTrue = () => setState(true);


const handleFalse = () => setState(false);
const handleToggle = () => setState(!state);

return [
state,
{
handleTrue,
handleFalse,
handleFalse,
},
];
};

Common questions

Powered by AI

Interceptors in a Redux application enhance request handling by allowing developers to globally intercept and modify requests or responses before they are handled by then or catch. This is advantageous for implementing features like authentication headers, logging, or error handling consistently across requests. However, their use can introduce complexity into the codebase by adding an additional layer of logic that can obscure request flows, and ill-implemented interceptors can lead to maintenance challenges and debugging difficulties if not properly managed .

The batch method in Redux improves performance by grouping multiple dispatch events into a single re-render cycle, thus reducing the number of state updates and corresponding UI re-renders. This approach is particularly beneficial for scaling applications as it minimizes computational overhead and enhances the responsiveness of the app by ensuring that the changes occur cohesively in one batch without intermediate renders .

Implementing CI/CD pipelines for JavaScript applications in React or Angular environments involves several challenges, including managing diverse and often rapidly changing dependencies, ensuring consistent build environments (handled through tools like Docker), and integrating automated testing frameworks such as Karma and Jasmine for Angular or Jest for React. Additionally, maintaining cross-browser compatibility is crucial, requiring thorough testing on various browsers. Considerations also include handling environment-specific configurations securely, optimizing build times, especially in larger applications, and effectively managing deployment scripts and processes to various environments (staging, production).

CSS combinators are essential in creating complex selectors by defining relationships between elements, allowing for more specific and granular styling. The descendant selector (space) selects elements nested under another, as in `.parent .child` to style child elements within a parent. The child selector (>) selects immediate children, used as `.parent > .child`. The adjacent sibling selector (+) targets the immediate sibling that directly follows an element, such as `.header + .content`. Finally, the general sibling selector (~) selects any sibling elements that follow, used as `.header ~ .content` to style elements that share the same parent. These combinators enhance the ability to target specific document elements precisely .

The useMemo hook in React memorizes the result of a function computation to avoid recalculations on re-renders unless the dependencies change. Syntax: `const cachedValue = useMemo(() => computeExpensiveValue(a, b), [a, b])`. The useCallback hook, on the other hand, caches the function reference itself to prevent unnecessary re-creations during component re-renders, which can be crucial for optimizing callback functions passed to child components. Syntax: `const cachedCallback = useCallback(() => { doSomething(a, b); }, [a, b])`. Use useMemo for avoiding expensive calculations and useCallback for avoiding unnecessary re-creation of functions .

In React 18, createRoot and hydrateRoot are introduced to handle the creation and hydration of render roots in a concurrent manner. createRoot is used to initialize an application with concurrent features providing a smoother user experience, whereas hydrateRoot is used for hydrating server-rendered applications into a DOM prepared by server-side rendering. They replace ReactDOM.render and ReactDOM.hydrate, enabling the new concurrent rendering capabilities provided by React 18, which were not possible with the older methods .

The Virtual DOM is a concept employed in React to improve application performance by minimizing direct manipulations of the actual DOM. By maintaining a lightweight representation of the DOM, React can efficiently compute differences between the current and previous states (using the diff algorithm) and update only the changed elements in the actual DOM. This process ensures that expensive DOM operations are reduced, leading to faster updates and improved application responsiveness .

Implicit type conversion in JavaScript occurs automatically, such as when using + between a string and a number ('5' + 2 results in '52'). This can lead to less predictable outcomes and potential confusion due to its non-obvious nature. Explicit type conversion, on the other hand, requires the use of inbuilt methods like Number(), String(), or parseInt(), allowing for greater control and predictability in the conversion process (e.g., Number('5') results in 5). Explicit conversions enhance code readability and reduce errors by making the transformation intentions clear .

Code-splitting in React optimizes application performance by breaking down the code into smaller bundles that are loaded on demand rather than as a single resource. React.lazy enables dynamic import of components, ensuring only the necessary code is loaded as users interact with the application. React.Suspense acts as a boundary to catch components that are being loaded, allowing developers to control what feedback or loading indicators to show during this process, thus improving user experience by reducing initial load times and bandwidth consumption .

Primitive data types in JavaScript, including string, number, null, undefined, and boolean, are immutable and stored directly in the memory stack, making their manipulation more straightforward and predictable. Non-primitive types like arrays, objects, and functions, on the other hand, are mutable and stored in the heap, allowing for dynamic data manipulation but necessitating careful memory management to avoid memory leaks due to their reference-based nature .

You might also like