toFixed ( 3 ) // -> 0.787 // It looks like it's just a 5 when you expand to the // limits of 64-bit (double-precision) float accuracy ( 0.7875 ). Confirm the odd result of rounding a 5 down ( 0.7875 ). However, when we pass undefined, we will get NaN. The value undefined is assigned to formal arguments when there are no actual arguments, so you might expect that Number without arguments takes undefined as a value of its parameter. If we don't pass any arguments into the Number constructor, we'll get 0. You should watch very carefully for the above examples! The behaviour is described in section 7.2.15 Abstract Equality Comparison of the specification. -> is used to show the result of an expression. ⚠️ Note: If you enjoy reading this document, please, consider supporting the author of this collection. You're probably going to find something new. If you are a professional developer, you can consider these examples as a great reference for all of the quirks and unexpected edges of our beloved JavaScript. I hope these notes will motivate you to spend more time reading the specification. If you are a beginner, you can use these notes to get a deeper dive into JavaScript. Just because it's fun to learn something that we didn't know before. The primary goal of this list is to collect some crazy examples and explain how they work, if possible. “Just for Fun: The Story of an Accidental Revolutionary”, Linus Torvalds
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |