Today, we had a productive Q&A session covering essential JavaScript concepts every developer should know. Whether you're preparing for interviews or brushing up on your fundamentals, these questions will help solidify your knowledge.
JavaScript Basics: Q&A
1. What is JavaScript?
JavaScript is a lightweight, interpreted programming language used to create dynamic and interactive web content like forms, animations, games, and more. It runs in the browser and can also be used on the server (Node.js).
2. What are the data types in JavaScript?
- Primitive: String, Number, Boolean, Undefined, Null, Symbol, BigInt
- Non-primitive: Object (includes Arrays, Functions)
3. Difference between var
, let
, and const
?
Keyword | Scope | Re-declaration | Hoisting | Mutable |
---|---|---|---|---|
var |
Function | ✅ Yes | ✅ Yes | ✅ Yes |
let |
Block | ❌ No | ✅ Yes (but not initialized) | ✅ Yes |
const |
Block | ❌ No | ✅ Yes (but not initialized) | ❌ No |
4. What is hoisting in JavaScript?
Hoisting is JavaScript's default behavior of moving declarations to the top of the current scope. Variables declared with var
and functions are hoisted.
5. What are template literals?
Template literals allow embedded expressions using backticks (\
) and ${expression}
syntax.
const name = "Tamil";
console.log(`Hello, ${name}!`);
6. What is the difference between ==
and ===
?
-
==
: Compares values after type coercion -
===
: Compares values and types (strict equality)
'5' == 5 // true
'5' === 5 // false
7. What is an arrow function?
A shorter syntax for writing functions:
const add = (a, b) => a + b;
8. What is the DOM?
DOM (Document Object Model) is a programming interface for HTML and XML documents. It represents the page structure as objects that JavaScript can manipulate.
9. What is an array in JavaScript?
An array is a special type of object used to store multiple values in a single variable.
let fruits = ["apple", "banana", "mango"];
console.log(fruits[1]); // banana
10. What is the difference between null
and undefined
?
-
undefined
: a variable declared but not assigned a value -
null
: an assignment value representing no value
11. What is a function in JavaScript?
A function is a reusable block of code designed to perform a particular task.
function sayHello() {
console.log("Hello!");
}
sayHello();
12. What is an object in JavaScript?
An object is a collection of key-value pairs used to store structured data.
let person = {
name: "Tamil",
age: 25
};
console.log(person.name); // Tamil
13. What are JavaScript operators?
Operators are used to perform operations on variables and values.
Examples:
- Arithmetic:
+
,-
,*
,/
- Comparison:
==
,===
,!=
- Logical:
&&
,||
,!
Final Thoughts
Understanding these JavaScript basics lays the groundwork for more advanced topics like ES6, async programming, frameworks, and full-stack development. Keep practicing and build small projects to solidify your learning.
Top comments (0)