Q1
console.log(018 - 015);
console.log("018" - "015");
Q2
const isTrue = true == [];
const isFalse = true == ![];
console.log ( isTrue + isFalse);
Q3
console.log(3 > 2 > 1);
Q4
console.log(typeof typeof 1);
Q5
console.log(('b' + 'a' + + 'a' + 'a').toLowerCase());
Q6
console.log(typeof NaN);
Q7
console.log(0.1 + 0.2 == 0.3);
Q8
const numbers = [33, 2, 8];
numbers.sort();
console.log(numbers[1])
Conclusion
What percentage of the eight questions were correct?
If you get all of them right, please leave a comment!
Top comments (4)
A1
A2
A3
This will log false. Here's why:
A4
This will log "string". Here's why:
A5
This will log "banana". Here's why:
A6
A7
A8
@itsjp
A1
An octal number is a number in JavaScript that has a leading zero.
018
is regarded as a decimal number, nevertheless, because it is an incorrect octal number.015
is13
in octal notation.018-015 = 18-13 = 5
as a result.A2
To begin with, allow me to clarify the first line:
true
and[]
are changed to integers because they are of different kinds. First to be evaluated arenumber(true)
andnumber([])
, which are1
and0
, respectively.const isTrue = false
since1 == 0
.Although
true
and![]
are both boolean values and are not converted to integers, it appears that the second line is the same. Additionally,![]
would befalse
because[]
is understood to betrue
.const isFalse = false
andconst isFalse = true
are the results.The final line,
console.log (isTrue + isFalse);
becomesconsole.log (false + false);
as a result of the foregoing.console.log (0 + 0);
becomes a number instead than false.Therefore, the solution is 0.
thank you for the corrections
😔