Explain me the output of the code below. Explain your answer?
Submitted by: Muhammadconsole.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
Submitted by: Muhammad
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
Submitted by: Muhammad
Read Online Full-Stack Developer Job Interview Questions And Answers
Top Full-Stack Developer Questions
☺ | Explain me what are the disadvantages of using JavaScript? |
☺ | Explain me which frameworks are you most familiar with? |
☺ | Can you write a function that can determine whether a string is a palindrome in under 100 characters? |
☺ | Tell us are you a team player? Give an example of a time when you had to resolve a conflict with another member on your team? |
☺ | Can you tell me what is starvation? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |