JavaScript Basics – Questions and Answers
1. What is JavaScript?
JavaScript is a programming language used to make web pages interactive. It can handle user
actions, manipulate web page content, validate forms, and communicate with servers.
2. Difference between HTML, CSS, and JavaScript?
HTML: Defines the structure of a web page.
CSS: Styles the web page (colors, layouts, fonts).
JavaScript: Adds interactivity and dynamic behavior.
3. What is a Variable?
A variable is a named container used to store data values that can be used and modified in a
program.
4. Difference between var, let, and const?
var: Function-scoped, can be redeclared and updated.
let: Block-scoped, can be updated but not redeclared in the same scope.
const: Block-scoped, cannot be reassigned after initialization.
5. What are Primitive Data Types?
Primitive data types are basic data types in JavaScript: String, Number, Boolean, Undefined, Null,
Symbol, and BigInt.
6. What is undefined?
undefined means a variable has been declared but has not been assigned a value.
7. What is null?
null represents an intentional absence of a value. It is assigned explicitly by the programmer.
8. What is typeof?
typeof is an operator used to determine the data type of a variable or value.
9. What is the difference between == and ===?
== (Loose Equality): Compares values after type conversion.
=== (Strict Equality): Compares both value and data type without type conversion.
10. What is the console used for?
The browser console is used for debugging JavaScript code, displaying messages, checking errors,
and testing code snippets.