1) When parsing a String into a number using the parseInt() method, we are advised to always provide the radix. Why is it so strongly recommended?
Ans:- If the radix parameter is omitted, JavaScript assumes the following:
If the string begins with "0x", the radix is 16 (hexadecimal)
If the string begins with "0", the radix is 8 (octal).
If the string begins with any other value, the radix is 10 (decimal)
if you try to parseInt("08") which result gives 0 because the string begins with "0" and converts next number into Octal number."8" is not include in octal number so result gives 0.
2)Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500?
Ans:- Yes. As per the operator priority the * and / has first priority rather than - and +. which start from left to right. hence first 115*4 is calculate which is equal to 460. the equation is now
460-4+88/2. now as per operator priority 88/2=44. now equation is 460-4+44=500
3)Will the following statement evaluate to true or false
(("red" != "car") || (3 >= 9)) && !(((10 * 2) == 100) && true) ?
Ans:- Above function evaluate to true.
("red"!="car") --> TRUE. Because of || to next not evaluate next condition that is (3>=9) and return true for (("red" != "car") || (3 >= 9)) statement.--i
(20==100)--> FALSE. Because of && it gives result False to ((10 * 2) == 100) && true) statement. !(False)--> TRUE --ii
so as per i and ii TRUE &&TRUE-->Evaluate TRUE.
Ans:- If the radix parameter is omitted, JavaScript assumes the following:
if you try to parseInt("08") which result gives 0 because the string begins with "0" and converts next number into Octal number."8" is not include in octal number so result gives 0.
2)Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500?
Ans:- Yes. As per the operator priority the * and / has first priority rather than - and +. which start from left to right. hence first 115*4 is calculate which is equal to 460. the equation is now
460-4+88/2. now as per operator priority 88/2=44. now equation is 460-4+44=500
3)Will the following statement evaluate to true or false
(("red" != "car") || (3 >= 9)) && !(((10 * 2) == 100) && true) ?
Ans:- Above function evaluate to true.
("red"!="car") --> TRUE. Because of || to next not evaluate next condition that is (3>=9) and return true for (("red" != "car") || (3 >= 9)) statement.--i
(20==100)--> FALSE. Because of && it gives result False to ((10 * 2) == 100) && true) statement. !(False)--> TRUE --ii
so as per i and ii TRUE &&TRUE-->Evaluate TRUE.
No comments:
Post a Comment