1. What are the core components of React Native?
Answer: Components are the building blocks of React Native; when combined, they make up the app as a whole. Some of the most common components are:
View : used to display the entire app layout
Text : used to display text
TextInput : used to input text
ScrollView : used to insert a scrolling container
StyleSheet : used to insert style objects
Image : used to render images
Button : used to insert buttons
2. What is the role of props in React Native?
Props provide properties to components inserted in a program, which makes components modifiable and customizable. For example, the same component might be used in different parts of an app. When we use props, we can alter the component’s appearance or behavior.
3. What is the role of Flexbox in React Native?
In React Native apps, Flexbox is used to provide a consistent layout across different screen types.
The Flexbox algorithm helps to structure the positioning of different components and create a responsive UI for the end user.
4. What is the state in React Native?
In React Native, the state refers to information about a property at a given time. Unlike props, the state is mutable; it can change. Typically, this will occur when a user interacts with the component.
For example, if your app had a filling form that users are invited to complete, the state of that component would change when the user types something in.
5. What engine does React Native use?
In React Native, JavaScript code runs through two engines:
JavaScriptCore: is used on iOS simulators and Android emulators; virtually all operations run through this engine
V8 : is used when Chrome debugging is being performed
6. What are the main performance issues in React Native and what causes them?
Some of the most common performance issues in React Native include:
High CPU usage: Offloading complex functions to the JavaScript thread can cause performance issues
Memory leak: Information can be lost in the Bridge during the transfer from the Primary to the React Native domains, especially in Android apps
Slow navigation: Multiple thread bridging can also cause slower navigation times
7. What is the role of hooks in React Native?
Hooks allow developers to ‘hook into’ existing components and access their state and lifestyle features.
Previously, these would not be accessible for use elsewhere. With hooks, developers can now tap into a component’s state and lifestyle
features without having to write a new class.
8. What is the role of fast refresh in React Native?
Fast refresh allows developers to get near-instant feedback on recent changes in their app.
Once ‘Enable fast refresh’ in the developer menu is toggled, any new edits in the program become visible within a few seconds
for an easy evaluation.
9. How can sensitive data be stored securely in React Native?
Most React Native data is stored in Async Storage. As an unencrypted, local form of storage, it’s not suitable for storing sensitive data such as tokens and passwords.
Alternatively, React Native Keychain offers a secure form of storage that also works similarly to Async Storage. For iOS, Keychain storage can be used to protect sensitive data, while Android developers can use Facebook Conceal and Android Keystone.
10. How are hot reloading and live reloading in React Native different?
Live reloading in React Native refreshes the entire app when a file changes, whereas hot reloading only refreshes the files that were changed.
When hot reloading is used on an app, the state remains the same and the developer is returned to the page they started on. The opposite is true for live reloading.
11.When would you use ScrollView over FlatList and vice versa?
ScrollView loads all data items on one screen for scrolling purposes. All the data is stored on RAM, which can cause performance issues for large amounts of data.
FlatList only displays items that are currently shown on the screen (10 by default), thus sidestepping any performance issues.
Therefore, it is best to use FlatList for large datasets, whereas ScrollView can be used for smaller datasets.
12.Could you explain how you would eliminate value duplicates in an array?
JavaScript developers can eliminate value duplicates in an array using several methods.
Doing so is crucial for improving the code’s performance and enhancing the user experience.
The first option they may consider is using Set, an inbuilt object that stores unique values in arrays.
It works with the set() constructor function, which creates an instance of unique values.
Alternatively, developers might implement the filter() method to achieve the same goal. For example,
if they want to create a new array that features unique values, they could use the following code snippet:
const arr = [1, 1, 2, 3, 3, 4];
const uniqueArray = arr.filter((value, index) => arr.indexOf(value) === index);
console.log(uniqueArray); // Output [1, 2, 3, 4]
13. Difference between “ == “ and “ === “ operators.
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.
Example:
var x = 2;
var y = "2";
(x == y) // Returns true since the value of both x and y is the same
(x === y) // Returns false since the typeof x is "number" and typeof y is "string"
14. Explain what is typecasting
15. Describe the differences between null and undefined in JavaScript. When would you use one over the other?
null is an intentional absence of any object value, while undefined represents the absence of a value in a variable. Use null when you want to explicitly indicate that a variable has no value, and use undefined when a variable has been declared but not assigned a value.
16. What are the differences between arrow functions and regular functions in JavaScript? When would you choose one over the other?
Arrow functions have a shorter syntax, do not bind their own this, and do not have their own arguments object. They are often preferred for concise and simple anonymous functions, while regular functions are necessary in certain situations, such as when you need access to this or arguments.
17.What is the difference between “var” and “let” keywords in JavaScript?
The var and let keywords are both used to declare variables in JavaScript. However, there are some key differences between the two keywords.
The var keyword declares a global variable, which means that the variable can be accessed from anywhere in the code. The let keyword declares a local variable, which means that the variable can only be accessed within the block of code where it is declared.
18.What are the different data types present in JavaScript?What are the different data types present in JavaScript?
There are three major data types present in JavaScript.
Primitive
Numbers
Strings
Boolean
Composite
Objects
Functions
Arrays
Trivial
Null
Undefined
19. What is the outcome of 5+3+"9"?
The 5 and 3, in this case, behave as integers, and "0" behaves like a string. Therefore 5 + 3 equals 8. The output is 8+"9" = 89.
20.Explain different functional components in JavaScript?
The functional components in JavaScript are-
First-class functions: functions are used as first-class objects. This means they can be passed as arguments to other functions, sent back as values from other functions, assigned to variables, or can even be saved as data structures.
Nested functions: These are defined inside other functions and called every time the main function is called.
21. What is the difference between synchronous and asynchronous programming?
In synchronous programming, the program execution occurs sequentially, and each statement blocks the execution until it is completed. In asynchronous programming, multiple tasks can be executed concurrently, and the program doesn’t wait for a task to finish before moving to the next one.
Synchronous coding example:
console.log("Statement 1");
console.log("Statement 2");
console.log("Statement 3");
Asynchronous code example:
console.log("Statement 1");
setTimeout(function(){
console.log("Statement 2");
}, 2000);
console.log("Statement 3");
22. How do you handle errors in JavaScript?
Errors in JavaScript can be handled using try-catch blocks.
The try block contains the code that may throw an error,
and the catch block handles the error and provides an alternative execution path.
23.What is the purpose of the map() function in JavaScript?
The map() function is used to iterate over an array and apply a transformation or computation on each element. It returns a new array with the results of the transformation.
const numbers = [1,2,3,4,5];
const squaredNumbers = numbers.map(function(num){
return num * num;
})
console.log(squaredNumbers); // Output : [1, 4, 9, 16, 25] ;
24.What is the purpose of the reduce() function in JavaScript?
The reduce() function is used to reduce an array to a single value by applying a function to each element and accumulating the result.
const numbers = [1,2,3,4,5];
const sum = numbers.reduce(function(){
return acc + num;
},0);
console.log(sum); //Output : 15
25.Write a JavaScript program to find the maximum number in an array.
Here's a simple JavaScript program that finds the maximum number in an array:
function findMaxNumber(arr) {
if (arr.length === 0) {
return "Array is empty";
}
let maxNumber = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] > maxNumber) {
maxNumber = arr[i];
}
}
return maxNumber;
}
// Example usage:
const numbers = [3, 7, 1, 9, 4, 6, 8];
const max = findMaxNumber(numbers);
console.log("The maximum number is:", max);
Advanced JavaScript Program to find the maximum number in an array
function findMaxNumber(arr) {
if (arr.length === 0) {
return "Array is empty";
}
return Math.max(...arr);
}
// Example usage:
const numbers = [3, 7, 1, 9, 4, 6, 8];
const max = findMaxNumber(numbers);
console.log("The maximum number is:", max);
26. Write a JavaScript program to reverse a given string.
function reverseString(str) {
return str.split('').reverse().join('');
}
// Example usage:
const originalString = 'Hello, World!';
const reversedString = reverseString(originalString);
console.log("Original String:", originalString);
console.log("Reversed String:", reversedString);
Other javascript coding interivew questions : https://www.keka.com/javascript-coding-interview-questions-and-answers
Write a code to eliminate value duplicates in an array?
Write a code to reverse a String?
0 comments:
Post a Comment