-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
Comments in JavaScript are lines that are not executed by the browser. They are meant to:
Make code easier to understand
Explain what a particular part of the code does
Temporarily disable a part of the code
JavaScript supports two types of comments:
Use //
to add a single-line comment.
// This is a single-line comment
let x = 5; // Declaring a variable
You can place it above a line or at the end of a line.
Use /* ... */
for multi-line comments. These are helpful when you want to comment out multiple lines of code or write detailed explanations.
/*
This is a multi-line comment.
It can span multiple lines.
*/
let y = 10;
✅ Documentation: Explain complex logic
✅ Debugging: Temporarily remove parts of code
✅ Collaboration: Help team members understand your code
✅ Clarity: Make your code cleaner and easier to maintain
You can use comments to disable code temporarily without deleting it.
// alert("This line is disabled temporarily");
console.log("This line runs");
Q1. How do you write a single-line comment in JavaScript above a variable declaration?
Q2. How do you write a single-line comment at the end of a code line that declares a variable age
with value 25
?
Q3. How can you write a multi-line comment that explains what a function does?
Q4. How do you comment out a single JavaScript statement that displays an alert?
Q5. How do you write a comment that spans multiple lines to describe the logic of a conditional statement?
Q6. How do you use a single-line comment to disable a console.log()
statement?
Q7. What is the correct way to use a multi-line comment to comment out two lines of code at once?
Q8. How do you place a comment in JavaScript inside a for
loop to explain each iteration?
Q9. How do you write a block of code and add comments above each line to explain what it does?
Q10. How do you temporarily disable an entire function using multi-line comments?
Q1: Which symbol is used to write a single-line comment in JavaScript?
Q2: Which of the following is the correct syntax for a multi-line comment?
Q3: What will happen to a line of code that is commented out using //?
Q4: Which of the following is NOT a valid use of JavaScript comments?
Q5: Which comment syntax would you use to explain a block of code with several lines?
Q6: Where can single-line comments be placed in JavaScript?
Q7: What does this line do: // let x = 10;?
Q8: What happens if you don’t close a multi-line comment?
Q9: How many lines can a multi-line comment span?
Q10: What is the primary purpose of JavaScript comments?