Dates and Numbers Flashcards
How to convert string to a number?
use Number(‘20’);
or use +’20”
I need to remove special characters from my int?
use Number.parseInt(‘23z’);
This works only when the number is beginning.
How to check is a value is a number?
use Number.isNan(‘234’);
but better to use isFinite() because is NaN returns values otehr than true or false like infinite
How to find square root of a number in JS?
use Math.sqrt();
How to find max / min of numbers?
Math.max(1,2,3,4,5);
How to generate random values?
Math.trunc(Math.randon() * 6) + 1
this will generate random values between 1 and 6
What are numeric separators?
we can add underscores(_) for better readability.
Example, const h = 345_455;
We cannot convert to string. Also, we cannot add _ next to . and at the end/beginning of the number.
What is the max int value in JS?
Interger value is 64 bit, in which 53 bits are used.
Number.MAX_SAFE_INTEGER
2 ** 53-1
What is BigInt?
Number which can be bigger than MAX_SAFE_INTEGER.
example, const i = 3543264563674567465467n we can also use BigInt();
How to create a date?
const now = new Date()
also, const d = new Date('August 20, 2021')
A few methods - d.ToFullYear()
d. Month()
etc. .
How to L10 the dates in JS?
Intl.DateTimeFormat(‘en_US’).fomat(date.now());
How to L10 numbers in JS?
Intl.NumberFomat(‘en_US’).fomat(12345);