Full-Stack Developer Question:
Download Job Interview Questions and Answers PDF
Explain me the output of the code below. Explain your answer?
Answer:
console.log(0.1 + 0.2);
console.log(0.4 + 0.1 == 0.5);
This is a trick question in that at first glance, you might expect the console to print out “0.3” and “true.” The correct answer is that you can’t know for sure, because of how JavaScript treats floating point values. In fact, in the above example, it will print out:
0.30000000000000004
false
console.log(0.4 + 0.1 == 0.5);
This is a trick question in that at first glance, you might expect the console to print out “0.3” and “true.” The correct answer is that you can’t know for sure, because of how JavaScript treats floating point values. In fact, in the above example, it will print out:
0.30000000000000004
false
Download Full-Stack Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
Tell me the output of the code below. Explain your answer? | Tell us the difference between classical inheritance and prototypal inheritance? |