1. JavaScript Basics (20 Questions)
Q1. What is JavaScript?
JavaScript is a high-level, interpreted, or just-in-time compiled programming language. It is primarily used to create interactive and dynamic content on websites. While it started as a browser-only language, it is now used on servers (Node.js), mobile apps, and even desktop applications.
Q2. Is JavaScript a single-threaded or multi-threaded language?
JavaScript is single-threaded, meaning it can only execute one task at a time in a single main thread. However, it handles concurrent operations (like API calls) using the Event Loop and Web APIs.
Q3. What is the difference between Java and JavaScript?
They are completely different languages. Java is an object-oriented, compiled language used for large-scale backend apps. JavaScript is a scripting language designed for the web. As the old joke goes: Java is to JavaScript what Car is to Carpet.
Q4. What are the key features of JavaScript?
- Lightweight: Small footprint.
- Interpreted: Code is executed line by line.
- Dynamic Typing: Variables can hold any data type.
- First-class functions: Functions are treated like variables.
Q5. What is “use strict” in JavaScript?
It is a directive that enables “Strict Mode.” It catches common coding mistakes and prevents the use of potentially unsafe features (like using undeclared variables).
“use strict”;
x = 10; // Error: x is not defined
Q6. What are the different ways to include JavaScript in HTML?
- Inline: Inside HTML attributes (e.g., onclick).
- Internal: Inside <script> tags in the head or body.
- External: Using the <script src=”file.js”></script> tag.
Q7. What are the primary data types in JavaScript?
JavaScript has Primitives (String, Number, Boolean, BigInt, Undefined, Null, Symbol) and Reference types (Objects, Arrays, Functions).
Q8. What is the difference between client-side and server-side JavaScript?
Client-side JS runs in the user’s browser (e.g., DOM manipulation). Server-side JS runs on the server (e.g., Node.js), handling databases and file systems.
Q9. What is a transpiler in JavaScript?
A transpiler (like Babel) takes modern JavaScript code (ES6+) and converts it into older versions of JavaScript that older browsers can understand.
Q10. What is an Engine in JavaScript?
It is a program that executes JavaScript code. The most famous is Google Chrome’s V8 Engine. Others include SpiderMonkey (Firefox) and JavaScriptCore (Safari).
Q11. Explain the concept of a “High-level language.”
It means the language is designed to be easy for humans to read and write. It abstracts away complex hardware details like memory management.
Q12. What are comments in JavaScript?
Comments are notes for developers that the engine ignores.
- Single line: // text
- Multi-line: /* text */
Q13. What is a JavaScript literal?
A literal is a fixed value written directly in the code.
let name = “CodeXRush”; // String literal
let age = 25; // Number literal
Q14. What is the difference between an expression and a statement?
An expression produces a value (e.g., 2 + 2). A statement performs an action (e.g., if (x > 5) { … }).
Q15. How do you output data in JavaScript?
- console.log(): For debugging.
- alert(): For simple pop-ups.
- document.write(): For testing purposes only.
- innerHTML: To update HTML content.
Q16. Is JavaScript case-sensitive?
Yes. myVariable and myvariable are treated as two completely different identifiers.
Q17. What are Reserved Words?
These are words you cannot use as variable names because they have special meaning to the language (e.g., break, for, while, class).
Q18. What is a Polyfill?
A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it.
Q19. What is the purpose of the semi-colon in JavaScript?
Semi-colons are used to separate statements. While JavaScript has Automatic Semicolon Insertion (ASI), it is a best practice to add them manually to avoid bugs.
Q20. What is the difference between null and undefined?
undefined means a variable has been declared but has not yet been assigned a value. null is an assignment value that represents “no value” or “nothing.”




