JavaScript Comparison and Logical Operators
Comparison နဲ႔ Logical Operators ေတြကိုေတာ႔ ture or false ကိုစစ္ေဆးဖို႔အတြက္အသံုးျပဳၾကပါတယ္
Comparison Operators
Comparison Operators ေတြကို variable ေတြဒါမဟုတ္ value ေတြတူလားမတူလားဆိုတာကိုစစ္တဲ႔ logical statements ေတြမွာသံုးရပါတယ္
ဆိုပါစို႔ x တန္ဖိုး ကို 5 ေပးထားမယ္
Operator Description Example
== is equal to x = 8 is false
=== is exactly equal to (value and type) x===5 is true and x===='5' is false
!= is not equal x!=8 is true
> is greater than x>8 is false
< is less than x<8 is true
>= is greater than or equal to x>8 is false
<= is Less than or equal to x<=8 is true
ဘယ္လိုအသံုးျပဳမလဲဆိုတာကိုေအာက္မွာရွင္းျပထားပါတယ္
Comparison Operators ကို conditional statement ေတြမွာအသံုးျပဳရပါတယ္ ဘယ္လိုမ်ိဳးလဲဆိုေတာ႔ value ေတြကို compare လုပ္ျပီး
ထြက္လာတဲ႔ result ေတြအေပၚမွာမူတည္ပါတယ္
ဥပမာ ထမင္းစားျပီးေရေသာက္ ဒါမဟုတ္ရင္ ထမင္းမစားဘူးဆိုရင္ေခါက္ဆြဲစားလိုမ်ိဳးပါ
if( eat>=true) document.write("Do you want to drink water") ;
conditional statement အေၾကာင္းကိုေနာက္လာမယ္႔အခန္းေတြမွာရွင္းျပေပးပါမယ္
ေနာက္တစ္ခုက Logical Operator ပဲ႔ျဖစ္ပါတယ္
ူLogical operator ကိုေတာ႔ကၽြန္ေတာ္တို႔က တန္ဖိုးေတြ ဒါမဟုတ္ variable ေတြၾကားမွာ logical အေနနဲ႔ဆံုးျဖတ္ေပးရတာေတြပါ
ဆိုပါစို႔ x တန္ဖိုးကို 6 လိုေပးျပီး y တန္ဖိုးကို 3 ဆိုျပီးေပးထားမယ္
ေအာက္မွာ Logical operator ရဲ႕အလုပ္လုပ္ပံုကိုေလ႔လာၾကည္ပါ
Operator Description Examples
&& and (ႏွင္႔) (x<10 && y>1) is true
|| or(သို႔မဟုတ္) (x==5||y==5) is true
! not(မဟုတ္ဘူးဆိုရင္) (!(x==y) is true
လာျပန္ျပီေနာက္တစ္ခုက Conditional Operator
JavaScript မွာလည္း Conditional operator ပါ၀င္ပါတယ္ဒါကေတာ႔ အခ်ိဳ႕အေျခေနေတြမွာ variable ထဲကို တန္ဖိုးေတြကို assign လုပ္တာပါပဲ႔
Syntax
variable=(condition)?value1:value2
ဒါက တစ္ခုမဟုတ္ရင္ေနာက္တစ္ခုကိုစစ္တာပါ
ဥပမာ
ကၽြန္ေတာ္နာမည္က cyberoot ဆိုပါစို႔
message=(name=="cyberoot")?"I know you":"Who";
သူရဲ႕ လုပ္ေဆာင္ပံုကေတာ႔လြယ္လြယ္ေလးပါ
ပထမဆံုး နာမည္က cyberoot လားဆိုတာ စစ္ပါတယ္ အကယ္ရွ္ ဟုတ္ခဲ႔တယ္ဆိုရင္ I know you ဆိုတဲ႔ string ကိုအလုပ္လုပ္ျပီးမဟုတ္ဘူးဆိုရင္
သူေနာက္က Who ဆိုတဲ႔ string ကိုျပမွာပါ
အားလံုးျပီးသြားျပီဆိုရင္ နမူနာေလးတစ္ခုေလာက္အစမ္းလုပ္ၾကည္႔ရေအာင္
့
<html>
<head><title>Js Module by cyberoot</title>
<script type="text/javascript">
var name="cyberoot";
var password="hacker";
var address="cyberoot1@gmail.com";
if((name==='cyberoot')&&(password==="hacker")){
document.write("you are cyberoot");
alert("Welcome from" + address);
}else{
document.write("Sorry,You don't remember");
}
</script>
</head>
<body>
</body>
</html>
ကၽြန္ေတာ္ဒီေနရာမွတစ္ခုသတိေပးခ်င္တာက Webdeveloper အမ်ားစုက login form ေတြေရးတဲ႔ခါ == နဲ႔ပဲ႔ condition စစ္တတ္ပါတယ္
=== is more secure for your web for injector :) cos of your pass is string is good than letter for security
Thanks for Reading...
Cyberoot1@Gmail.com
cyberoot.blogspot.com
No comments:
Post a Comment
Thanks for your comments
Welcome from cyberoot