Java Interview Questions For Freshers


Java Interview Questions For Freshers

Java Interview Questions For Freshers

1. What is JavaScript?

Answer: JavaScript is a high-level, interpreted programming language that is primarily

used for building dynamic web pages and adding interactivity to websites.

2. Explain the difference between undefined and null.

Answer: undefined is a variable that has been declared but has not been assigned a

value, whereas null is an assignment value representing the absence of an object value.

3. What is the purpose of the typeof operator?

Answer: The typeof operator is used to determine the data type of a variable or

expression.

4. What is the DOM (Document Object Model)?

Answer: The DOM is a programming interface for web documents. It represents the

structure of a document as a tree of objects, where each object corresponds to a part of the

document, such as elements and attributes.

5. What is the difference between == and === in JavaScript?

Answer: == is the equality operator, which performs type coercion, while === is the strict

equality operator, which requires both value and type to be the same for equality.

6. Explain the concept of closures in JavaScript.

Answer: Closures allow functions to access variables from their outer scope, even after

the outer function has finished executing.

7. What is an IIFE (Immediately Invoked Function Expression)?

Answer: An IIFE is a function that is defined and executed immediately after its creation.

8. What is the event delegation in JavaScript?

Answer: Event delegation is a technique where a single event listener is attached to a

common ancestor rather than to individual elements. This is particularly useful for dynamically

created elements.

9. How does hoisting work in JavaScript?

Answer: Hoisting is a JavaScript behavior where variable and function declarations are

moved to the top of their containing scope during compilation.

10. What is the difference between let, const, and var in variable declaration?

Answer: let and const are block-scoped, while var is function-scoped. Variables declared

with let can be reassigned, const variables cannot be reassigned, and var has no such

restriction.

11. What is the purpose of the this keyword in JavaScript?

Answer: The this keyword refers to the current context or object in which the code is

executing.

12. What is a promise in JavaScript?

Answer: A promise is an object representing the eventual completion or failure of an

asynchronous operation, and its resulting value.

13. Explain the concept of callback functions.

Answer: Callback functions are functions passed as arguments to another function to be

executed later, often used in asynchronous operations.

14. What is the difference between slice() and splice()?

Answer: slice() is used to extract a portion of an array without modifying the original

array, while splice() is used to add or remove elements from an array.

15. What is the purpose of the bind() method in JavaScript?

Answer: The bind() method is used to create a new function with a specified this value

and initial arguments.

16. What is the use of the map() function in JavaScript?

Answer: The map() function is used to create a new array by applying a provided

function to each element of an existing array.

17. How does the async/await feature work in JavaScript?

Answer: async/await is a syntax for working with asynchronous code. The async keyword

is used to define asynchronous functions, and await is used to wait for a promise to resolve.

18. What is the purpose of the localStorage and sessionStorage objects?

Answer: localStorage and sessionStorage are web storage objects used to store key-value

pairs locally on the client's browser. The data stored in localStorage persists even after the

browser is closed, while data in sessionStorage is only available for the duration of the page

session.

19. Explain the concept of prototypal inheritance in JavaScript.

Answer: Prototypal inheritance is a mechanism where objects can inherit properties and

methods from other objects through a prototype chain.

20. How does the event.preventDefault() method work?

Answer: event.preventDefault() is used to prevent the default behavior of an event, such

as preventing a form from being submitted or a link from being followed.

21. What is the purpose of the Object.keys() method?

Answer: Object.keys() is used to return an array of a given object's own enumerable

property names.

22. Explain the concept of AJAX in JavaScript.

Answer: AJAX (Asynchronous JavaScript and XML) is a technique used to make

asynchronous requests to a server from the client without reloading the entire page.

23. What is the purpose of the fetch() function in JavaScript?

oAnswer: The fetch() function is used to make network requests and returns a Promise

that resolves to the Response to that request.

24. What is the difference between arrow functions and regular functions?

Answer: Arrow functions do not have their own this and arguments, and they cannot be

used as constructors. They also have a shorter syntax.

25. What is the role of the NaN value in JavaScript?

Answer: NaN stands for "Not-a-Number" and is a special value representing an

unrepresentable value as a number. It is returned when a mathematical operation cannot

produce a meaningful result.

26. How does the JSON.stringify() method work?

 Answer: JSON.stringify() is used to convert a JavaScript object into a JSON string.

27. What is the purpose of the addEventListener() method?

Answer: addEventListener() is used to attach an event handler function to an HTML

element.

28. Explain the concept of the Same-Origin Policy in the context of JavaScript.

Answer: The Same-Origin Policy is a security measure that restricts web pages from

making requests to a domain that is different from the one that served the web page.

29. What is a callback hell? How can it be avoided?

Answer: Callback hell (or the Pyramid of Doom) is a situation where multiple nested

callbacks make the code hard to read and maintain. It can be avoided by using techniques like

modularization, Promises, or async/await.

30. What is the purpose of the Array.isArray() method?

Answer: Array.isArray() is used to check whether an object is an array.


0 Comments:

Post a Comment