Why itā€™s return ā€œtruefalseā€? I think this is due to the nuances of data types | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Why itā€™s return ā€œtruefalseā€? I think this is due to the nuances of data types

https://code.sololearn.com/W9jV9Wk4lIbM/?ref=app

3rd Jun 2020, 12:14 PM
Aleks
5 Respostas
+ 1
Aleks this is a common problem in javascript calculations. Try console.log(0.1*0.2); and you will see. Google javascript floating point precision for more info!
3rd Jun 2020, 12:47 PM
Thį»‘ng Nguyį»…n
Thį»‘ng Nguyį»…n - avatar
+ 2
ThĆ“ng NguyĆŖn, ODLNT, thank you for the answers!
3rd Jun 2020, 12:56 PM
Aleks
+ 1
Aleks it's because === is a comparison operator. So it will return true or false. More info here: https://www.w3schools.com/js/js_comparisons.asp
3rd Jun 2020, 12:21 PM
Thį»‘ng Nguyį»…n
Thį»‘ng Nguyį»…n - avatar
3rd Jun 2020, 12:50 PM
ODLNT
ODLNT - avatar
0
I mean - why first comparison return true, but second - return false. They have identical structure. The only explanation that i see is related to data conversion when moving to integer values
3rd Jun 2020, 12:35 PM
Aleks