Example Code
var x, y, z; //Statement 1x = 5; //Statement 2y = 6; //Statement 3z = x + y; //Statement 4
JavaScript Programs
Computer Program ဆိုတာဟာ ကွန်ပျူတာ "ဘာတွေလုပ်ဆောင်ရမယ်" ဆိုတဲ့ "ညွှန်ကြားချက်" တွေကို စုစည်းထားတဲ့ အစုအဝေးတစ်ခုဖြစ်ပါတယ်။
အဲဒိ "ညွန်ကြားချက်" တွေကို "Statement" လိုခေါ်ပါတယ်။
Program ဆိုတာကတော့ အဲဒိ Statement တွေစုစည်းထားတာကို ခေါ်တာဘဲ ဖြစ်ပါတယ်။
JavaScript Statement
JavaScript Statement တစ်ခုမှာ အောက်ပါ အစိတ်အပိုင်းတွေ ပါဝင်ပါတယ်။
Values, Operators, Expressions, Keywords and Comments.
Statement တွေကို ရေးထားစဉ်က အတိုင်း တစ်ကြောင်းပြီး တစ်ကြောင်းအလုပ် လုပ်သွားပါတယ်။
Semicolons (;)
JavaScript Statement တစ်ခုနှင့် တစ်ခုကို Semicolon (;) က ပိုင်းခြားပေးပါတယ်။
Semicolon (;) ကို JS Statemnt တွေရဲ့ နောက်ဆုံးမှာ ထည့်ပေးရပါမယ်။
Example Code
var a, b, c; //Declear 3 Variablea = 5; //Assign to value 5 to ab = 6; //Assign to value 6 to bc = a + b; //Assign to sum of a and b to c
တစ်ခုထက်ပိုတဲ့ Statement တွေ စာတစ်ကြောင်းထဲမှာ ရှိနေရင်လည်း Semicolon (;) ကအလုပ်လုပ်ပါတယ်။
Example Code
var a, b, c;; a = 5; b = 6; c = a + b;
ပုံမှန်အားဖြင့်တော့ Semicolon (;) တွေမရေးထည့်ရင်လည်း Webpage မှာ ကောင်းကောင်းအလုပ်လုပ် ပါတယ်။
ဒါပေမယ့် Semicolon (;) တွေထည့်ရေးတာဟာ ကောင်းတဲ့အလေ့အကျင့် တစ်ခုပါ။ ကုဒ်ဖတ်ရတာနဲ့ နောက်ပိုင်း ပြန်ပြင်ဆင်ရတာတွေမှာ အထောက်အကူဖြစ်ပါတယ်။
JavaScript White Space
White Space ဆိုတာက ကုဒ်တွေရေးတဲ့အခါမှာ ရှင်းရှင်းလင်းလင်း မြင်ရအောင် ရေးတဲ့ Space တွေ၊ Tab တွေကို ခေါ်တာဖြစ်ပါတယ်။
JavaScript ဟာ White Space တွေကို ကျော်ပြီး အလုပ်လုပ်ပါတယ်။ ဒီတော့ ဖတ်လို့အဆင်ပြေအောင် သင့်စိတ်ကြိုက်ရေးသားနိုင်ပါတယ်။
ဒီအောက်က ကုဒ် နှစ်ခုဟာ အတူတူဘဲ အဖြေထွက်ပါတယ်။
var person = "Zayar Aung";var person="Zayar Aung";
Operator (= + - * / ) များရဲ့ ရှေ့နှင့် နောက်မှာ Space ခံထားခြင်းဟာ အလေ့အကျင့်ကောင်းတစ်ခု ဖြစ်ပါတယ်။
var a = 5 + 6;
JavaScript Code Blocks
JavaScript Statement တွေများစွာကို Code Block ထဲမှာထည့်ပြီးတော့ အုပ်စုဖွဲထားနိုင်ပါတယ်။ အုပ်စုဖွဲ့တဲ့အခါမှာ Carly Brckets {...} ကို အသုံးပြုပါတယ်။
Code Block တွေသုံးရတဲ့ ရည်ရွယ်ချက်ကတော့ အတူတကွ အလုပ်လုပ်ဆောင်မယ့် JS Statement တွေကို သီသန့် ခွဲထုပ် အုပ်စုဖွဲထားဖို့ဘဲ ဖြစ်ပါတယ်။
ဥပမာ အားဖြင့် ပြောရမယ်ဆိုရင်တော့ JS Function တွေမှာ Code Block တွေကို တွေ့နိုင်ပါတယ်။
Example Code
function myFunction(){document.getElementById("demo1").innerHTML = "Hello Dolly!";document.getElementById("demo2").innerHTML = "How are you?";}
ဒီပေ့မှာတော့ Code Block ဆိုတာ အတူအလုပ်လုပ်ဆောင်ရမယ့် ကုဒ်တွေကို အုပ်စုဖွဲလိုက်တယ်။ အဲဒီလို အုပ်စုဖွဲဖို့အတွက် Carly Brackets {...} ကိုသုံးတယ် ဆိုတာ သိရင် ရပါပြီ။
JS Function တွေအကြောင်းကို နောက်အခန်းတွေမှာ ပိုမိုလေ့လာရပါဦးမယ်။
JavaScript Keywords
နောက်ပိုင်းမှာ JavaScript Keywords တွေကို အသေးစိတ် လေ့လာရပါမယ်။ ဒီပေ့မှာတော့ ရင်းနှီးယုံသာ ကြည့်ထားရင်ရပါပြီ။
JavaScript Keywords အပြည့်အစုံစာရင်းကို ကြည့်လိုတယ်ဆိုရင် တော့ JavaScript Keyword List မှာကြည့်ရှုနိုင်ပါတယ်။
အောက်ကတော့ အသုံးများတဲ့ JS Keywords List ဘဲဖြစ်ပါတယ်။
| Keyword | Description |
|---|---|
| break | Switch တွေ၊ Loop တွေကို ရပ်တန့်စေဖို့အတွက်သုံး |
| continue | Loop တွေထဲကနေ ထွက်ခွာသွားဖို့နှင့် အစကနေ ပြန်စဖို့အတွက်သုံး |
| debugger | Stops the execution of JavaScript, and calls (if available) the debugging function |
| do...while | Executes a block of statements, and repeats the block, while a condition is true |
| for | Marks a block of statements to be executed, as long as a condition is true |
| function | Declares a function |
| if...else | Marks a block of statements to be executed, depending on a condition |
| return | Exits a function |
| switch | Marks a block of statements to be executed, depending on different cases |
| try...catch | Implements error handling to a block of statements |
| var | Declares a variable |
JavaScript Keyword ကို Veriable Name , Function Name များအဖြစ် အသုံးပြုလို့ မရပါဘူး။
No comments:
Post a Comment