# JavaScript基本语法指南：注释用法实例

2021年3月17日14:33:38 发表评论 303 次浏览

``// For single line comment``
``````/* For block of lines comment
...
...
*/``````

``````<!DOCTYPE html>
< html >

< title >
</ title >

< script >

// Function to add two numbers

// Declare three variables
var x, y, z;

// Input a number and store it into variable x
x = Number( document.getElementById("num1").value );

// Input a number and store it into variable x
y = Number( document.getElementById("num2").value );

// Sum of two numbers
z= x +y;

// Return the sum
document.getElementById("sum").value = z;
}
</ script >

< body >
Enter the First number: < input id = "num1" >< br >< br >
Enter the Second number: < input id = "num2" >< br >< br >

< button onclick = "add()" >
Sum
</ button >

< input id = "sum" >
</ body >

</ html >``````

``````<!DOCTYPE html>
< html >

< title >
</ title >

< script >

/* Script to get two input from user

/* Declare three variable */
var x, y, z;

/* Input the two nos. num1, num2
Input num1 and store it in x
Input num2 and store it in y
The sum is stored in a variable z*/
x = Number(document.getElementById("num1").value);
y = Number(document.getElementById("num2").value);
z = x + y;

document.getElementById("sum").value = z;
}
</ script >

< body >
Enter the First number : < input id = "num1" >< br >< br >
Enter the Second number: < input id = "num2" >< br >< br >

< button onclick = "add()" >
Sum
</ button >

< input id = "sum" >
</ body >

</ html >``````

``````<!DOCTYPE html>
< html >

< title >
</ title >

< script >

var x, y, z;

x = Number( document.getElementById("num1").value );

y = Number( document.getElementById("num2").value );

z= x +y;

// Comment the code section
//document.getElementById("sum").value = z;
}
</ script >

< body >
Enter the First number: < input id = "num1" >< br >< br >
Enter the Second number: < input id = "num2" >< br >< br >

< button onclick = "add()" >
Sum
</ button >

< input id = "sum" >
</ body >

</ html >``````