1. How is Java different from JavaScript?
Ans:
Java is a compiled language that needs the JVM to run and is mostly used for big applications. The primary purpose of JavaScript, an interpreted language that runs in web browsers and servers like Node.js, is to create interactive websites. Though their names are similar, they work very differently.
2. What types of data does JavaScript have?
Ans:
JavaScript has simple data types like strings, numbers, booleans, null, undefined, BigInt and Symbol for basic values. It also has complex types like objects, arrays and functions, which can hold multiple values. Knowing these helps you organize and manage data well.
3. Which programming languages use Object-Oriented Programming (OOP)?
Ans:
Many languages like Java, C++, Python, C#, Ruby and JavaScript use OOP. They organize code into classes and objects, use inheritance and encapsulation to make reusable and modular programs that are easier to maintain and build.
4. What distinguishes JavaScript's let and var variables?
Ans:
Both let and var create variables, but var is scoped to the whole function, while let is limited to the block its used in. Let doesn’t allow redeclaring the same variable in a scope which helps prevent bugs. Using let is now preferred for cleaner code.
5. What does NaN mean in JavaScript?
Ans:
NaN means “Not-a-Number.” It shows up when a calculation doesn’t result in a valid number, like dividing zero by zero. It helps programmers spot and fix errors in math-related code.
6. What’s the difference between passing by value and passing by reference?
Ans:
Passing by value means giving a copy of the data to a function, so the original stays the same. Passing by reference means giving the function the actual data location, so changes inside the function affect the original. This matters when handling data carefully.
7. What is strict mode in JavaScript?
Ans:
Strict mode is a way to write safer JavaScript by adding 'use strict' at the top of your code. It stops you from using undeclared variables and other risky actions, helping to avoid common bugs and making your code more secure.
8. What does the “this” keyword mean in JavaScript?
Ans:
The “this” keyword refers to object currently running a function. In object methods, it points to that object. In normal functions, it can be undefined in strict mode. In arrow functions, “this” takes the value from the surrounding code.
9. What are design patterns in JavaScript?
Ans:
Design patterns are common solutions to programming problems that keep code organized and easy to maintain. Examples include patterns like Module, Singleton, Observer, Factory and Prototype. They help developers write better, scalable applications.
10. What is DOM in the JavaScript?
Ans:
The DOM (Document Object Model) is the way JavaScript represents a webpage as a tree of objects. By changing the DOM, JavaScript can update the page’s content, structure and style on the fly, making websites interactive and dynamic.