Skip to content

Latest commit

 

History

History
64 lines (61 loc) · 1.18 KB

4. JavaScript Comments.md

File metadata and controls

64 lines (61 loc) · 1.18 KB

4. JavaScript Comments

Write Comment

// program to take the user's name
let name = prompt("Enter your name: ");
console.log("Name: " + name);

Output

Enter your name: James
Name: James

Another comment example

// program to take the user's name
let name = prompt("Enter your name: ");  // take input
console.log("Name: " + name); // print the name variable

Output

Enter your name: James
Name: James

Prevent Executing Code Using Comments

// program to take user's name and age
let name = prompt("Enter a name: ");
// let age = prompt("Enter age: ");
console.log("name: " + name);
// console.log("age:", age);

Output

Enter name: Sarah
name: Sarah

JavaScript Multiline comments

/*This program is used to take name of the user
You can get the name from the user
and display the result*/ 

let name = prompt("Enter your name:");
console.log("Name " + name);

Output

Enter your name: Sarah
Name Sarah

Programmiz Quiz

Which of the following operators is used as a comment in JavaScript?

1. //
2. <!-- →
3. #
4. **

Answer: 1