Dates and Numbers Flashcards

1
Q

How to convert string to a number?

A

use Number(‘20’);

or use +’20”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

I need to remove special characters from my int?

A

use Number.parseInt(‘23z’);

This works only when the number is beginning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to check is a value is a number?

A

use Number.isNan(‘234’);

but better to use isFinite() because is NaN returns values otehr than true or false like infinite

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to find square root of a number in JS?

A

use Math.sqrt();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to find max / min of numbers?

A

Math.max(1,2,3,4,5);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to generate random values?

A

Math.trunc(Math.randon() * 6) + 1

this will generate random values between 1 and 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are numeric separators?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the max int value in JS?

A

Interger value is 64 bit, in which 53 bits are used.

Number.MAX_SAFE_INTEGER

2 ** 53-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is BigInt?

A

Number which can be bigger than MAX_SAFE_INTEGER.

example, const i = 3543264563674567465467n
we can also use BigInt();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to create a date?

A

const now = new Date()

also, 
const d = new Date('August 20, 2021')

A few methods - d.ToFullYear()

d. Month()
etc. .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to L10 the dates in JS?

A

Intl.DateTimeFormat(‘en_US’).fomat(date.now());

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to L10 numbers in JS?

A

Intl.NumberFomat(‘en_US’).fomat(12345);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly