The methods under the math object must be very familiar to everyone, but the attributes of the math object are rarely used. These attributes are some common mathematical result sets, it can be understood as a group of constants, although this concept is not found in the current JavaScript.
Attribute |
Approximate value |
Description |
Math. e |
2.718 |
Constant E |
Math. ln2 |
0.693 |
Natural logarithm of 2 |
Math. ln10 |
2.302 |
Natural logarithm of 10 |
Math. log2e |
1.442 |
Base-2 logarithm of E |
Math. log10e |
0.434 |
Base-10 logarithm of E |
Math. Pi |
3.14159 |
Constant π |
Math. sqrt1_2 |
0.707 |
Square root of 0.5 |
Math. sqrt2 |
1.414 |
Square root of 2 |
Knowing and even remembering them, maybe they will be used at any time. Calling them is much more efficient than creating a method.
It is worth noting that the above values are all about values, and there is a slight difference in the precision obtained in different browsers, which needs to be controlled during use.