Javascript Comments
Javascript comments ေတြကို code ေတြဖတ္တဲ႔အခါ ပိုျပီးအဆင္ေျပေအာင္သံုးၾကပါတယ္
comments ေတြကို Javascript ရဲ႕လုပ္ေဆာင္ခ်က္ေတြကို ရွင္းျပဖို႔အတြက္ သံုးၾကပါတယ္ ျပီးေတာ႔ code ေတြဖတ္တာအဆင္ေျပေအာင္ေပါ႔
Single line comments ကို // နဲ႔စပါတယ္
ေအာက္မွာဥပမာေရးျပထားပါတယ္
<script type="text/javascript">
//I am comment for javascript and write header
document.write("<h1>I am Header</h1>");
//I am paragraph
document.write("<p>This is a paragraph</p>");
</script>
Javascript Multiline Comments
Multiline Comments ကို /* နဲ႔ စျပီး အဆံုးမွာေတာ႔ */ နဲ႔ အဆံုးသတ္ပါတယ္
ေရးပံုကေတာ႔ ေအာက္မွာပါ
<script type="text/javascript">
/*
The code below will write
one heading and two paragraphs
*/
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
</script>
Using Comments to Prevent Execution
Code line တစ္ေၾကာင္းစီကို error ရွာတဲ႔အခါ သို႔ debug လုပ္တဲ႔အခါမွာလည္း Comment ကအသံုး၀င္ပါတယ္
ေအာက္မွာေရးထားပံုကိုၾကည္႔ပါ
<script type="text/javascript">
//document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
</script>
ေနာက္တစ္ခု
<script type="text/javascript">
/*
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
*/
</script>
Note:Comments ေတြကို code line နဲ႔ေနာက္ဆံုးမွာလည္းေရးသားနိုင္ပါတယ္
<script type="text/javascript">
document.write("Hello"); // Write "Hello"
document.write(" ဆိုက္ဘာရု!"); // Write " ဆိုက္ဘာရု!"
</script>
No comments:
Post a Comment
Thanks for your comments
Welcome from cyberoot