If You Can Answer These 7 Questions Correctly You’re Decent at JavaScript
Volodymyr
JavaScript can be a little tricky sometimes, even when you’re dealing with simple-looking problems.
Here are seven questions that test different parts of JavaScript.
They look easy, but they can catch you off guard! If you can answer these, you’ve got a good handle on JavaScript!
JOIN MY FREE WEEKLY WEBDEV NEWSLETTER!
Question 1: What’s the Result of 0.1 + 0.2 === 0.3?
console.log(0.1 + 0.2 === 0.3);
Answer:
The result is false.
Explanation:
In JavaScript, numbers with decimals (called floating-point numbers) don’t always add up the way we expect.
Due to how floating-point numbers are represented in JavaScript, 0.1 + 0.2 doesn’t exactly equal 0.3. Instead, it results in 0.30000000000000004, leading to the comparison being false. This issue comes from the binary approximation of decimal numbers in JavaScript.
Question 2: What’s the Result of "5" + 3 and "5" - 3?
console.log("5" + 3); console.log("5" - 3);