xxxxxxxxxx
/*
The code below will change
the heading with id = "myH"
and the paragraph with id = "myP"
in my web page:
*/
document.getElementById("myH").innerHTML = "My First Page";
document.getElementById("myP").innerHTML = "My first paragraph.";
let x = 5; // Declare x, give it the value of 5
let y = x + 2; // Declare y, give it the value of x + 2
// Change heading:
document.getElementById("myH").innerHTML = "My First Page";
// Change paragraph:
document.getElementById("myP").innerHTML = "My first paragraph.";
xxxxxxxxxx
// This is how you comment a single line in JavaScript
/*
This is how you comment
multiple lines in
JavaScript
*/
xxxxxxxxxx
You can use double slash //for single line of code
//console.log("Hello world!")
If you want to comment out multiple lines of code here is the two ways.
First: everything between /**/
/*
console.log("Hello world1!")
console.log("Hello world2!")
console.log("Hello world3!")
*/
Second: select all lines, which you want to comment out and use:
ctrl+k+c //to comment out
ctrl+k+u //to uncomment
//console.log("Hello world1!")
//console.log("Hello world2!")
//console.log("Hello world3!")
xxxxxxxxxx
//short comment
//loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment
/*
multiple
line
comment
*/
//Comments won't be shown on the page or effect the code but will remain in website code. Useful for commenting what is the code for