JavaScript တွင် ယုတ္တိတန်သော အမျိုးအစားသို့ ပြောင်းလဲခြင်း

ယခု အခြားအချက်အလက်အမျိုးအစားများကို ယုတ္တိတန်သောအမျိုးအစားသို့ ပြောင်းလဲခြင်းကို လေ့လာကြပါစို့။ ထိုသို့ပြောင်းလဲခြင်းကို Boolean လုပ်ဆောင်ချက်ကို အသုံးပြု၍ လုပ်ဆောင်ပါသည်။ ယုတ္တိတန်သောအမျိုးအစားသို့ ပြောင်းလဲသောအခါ false ကိုပေးသော တန်ဖိုးများမှာ အောက်ပါအတိုင်းဖြစ်သည် -

javascriptconsole.log(Boolean(0));          // false
console.log(Boolean(-0));         // false
console.log(Boolean(+0));         // false
console.log(Boolean(null));       // false
console.log(Boolean(false));      // false
console.log(Boolean(NaN));        // false
console.log(Boolean(undefined));  // false
console.log(Boolean(''));         // false

JavaScript ရှိ အခြားတန်ဖိုးအားလုံး (အခြားဘာသာစကားများတွင် ဤသို့မဟုတ်ပါ) သည် true ကို ပေးပါသည်။ အောက်ပါတန်ဖိုးများသည် true သို့ ပြောင်းလဲသော်လည်း သံသယဖြစ်စရာဖြစ်နိုင်သည် -

javascriptconsole.log(Boolean(-1));          // true
console.log(Boolean(Infinity));    // true
console.log(Boolean(-Infinity));   // true

အောက်ပါတန်ဖိုးများသည် ကိုးကားချက်များထဲတွင် ထည့်ထားသောကြောင့် စာကြောင်းများဖြစ်ပြီး true သို့လည်း ပြောင်းလဲပါသည် -

javascriptconsole.log(Boolean('0'));         // true
console.log(Boolean('false'));     // true
console.log(Boolean('NaN'));       // true
console.log(Boolean('null'));      // true
console.log(Boolean('undefined')); // true
Задание 1

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(3);
alert(test);
Задание 2

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(0);
alert(test);
Задание 3

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(-1);
alert(test);
Задание 4

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(-0);
alert(test);
Задание 5

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(+0);
alert(test);
Задание 6

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('abc');
alert(test);
Задание 7

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('');
alert(test);
Задание 8

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('0');
alert(test);
Задание 9

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(true);
alert(test);
Задание 10

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(false);
alert(test);
Задание 11

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('true');
alert(test);
Задание 12

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('false');
alert(test);
Задание 13

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(null);
alert(test);
Задание 14

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('null');
alert(test);
Задание 15

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(undefined);
alert(test);
Задание 16

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('undefined');
alert(test);
Задание 17

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(NaN);
alert(test);
Задание 18

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean('NaN');
alert(test);
Задание 19

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(3 * 'abc');
alert(test);
Задание 20

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(Infinity);
alert(test);
Задание 21

ကုဒ်ကို မစတင်မီ၊ မျက်နှာပြင်ပေါ်တွင် မည်သည်ကို ပြသမည်ကို ဆုံးဖြတ်ပါ -

javascriptlet test = Boolean(1 / 0);
alert(test);