1. What is JavaScript?
JavaScript is a high-level, versatile programming language primarily used to create interactive and dynamic web applications. It can run both in the browser and on the server (using environments like Node.js).
2. What is the difference between == and === in JavaScript?
In JavaScript, == is the loose equality operator, which compares two values for equality after performing type coercion if necessary. This means it converts the operands to the same type before performing the comparison.
=== is the strict equality operator, which compares both the values and their types, without performing type conversion.
3. What Are the Different Data Types in JavaScript?
JavaScript has seven primitive data types:
- BigInt
- Boolean
- Number
- Null
- String
- Symbol
- Undefined
It also has two compound data types:
- Object
- Array
4. What is a Variable Scope in JavaScript?
In JavaScript, we have each variable are accessed and modified through either one of the given scope:
- Global Scope: Outermost level (accessible everywhere).
- Local Scope: Inner functions can access variables from their parent functions due to lexical scoping.
- Function Scope: Variables are confined to the function they are declared in.
- Block Scope: Variables declared with let or const are confined to the nearest block (loops, conditionals, etc.).