Part 6- A Smarter Way to Learn JavaScript Flashcards

1
Q

Code for converting a string that’s a number to its equivalent number

A

Number(variableName);

(the name of the variable is at the end)

Note: works for integer strings and floating-point number strings

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

Code for converting a number to a string?

A

variableName.toString();

(the name of the variable is at the beginning)

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

Limit the decimal places on a number?

A

varName.toFixed(# of digits);

HOWEVER this also converts it to a string

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

What is the code to get a new date object and assign it to the variable “now”?

A

var now = new Date();

*notice that “Date” is capitalized

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

In a Date object, what number is assigned to Sunday?

A

0

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

In a Date object, what number is assigned to Saturday?

A

6

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

In a Date object, what number is assigned to Thursday?

A

4

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

How would I extract the day of the week from a Date object called “party”?

A

party.getDay();

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

What’s the difference between these?
getDate();
getDay();

A

Date is day of the month
It’s indexed with 1

Day is the day of the week
It’s indexed with 0

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

What does getTime() return from a Date object??

A

The milliseconds since midnight, January 1, 1970

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

What does getMonth() return from a Date object??

A

A number. 0 for January, 1 for Feb etc. until December, which is 11

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

What’s the code that returns the year from a Date object “d”?

A

d.getFullYear();

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

What’s the code to return the smallest unit of time that JavaScript recognizes from a Date object “d”?

A

d.getMilliseconds()

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

Before you can getDate, getHours, or getFullYear, what must you do?

A

Get a Date object:
var d = new Date();

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

What is the code to return the hour from a Date object “d”?

A

d.getHours();

*Note that HOURS is plural. MINUTES, SECONDS, and MILLISECONDS

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

What is tricky about returning getMonth() from a Date object?

A

The numbers are off because the counting starts at zero. So January is zero and December is 11.

17
Q

What is tricky about returning getDate() from a Date object?

A

The count starts at 1, not zero.
This is different from all of the other Date object parts, like MONTH, HOURS, etc.

18
Q

How do you create a Date object for a time that is not right now?

A

new Date(“date info here”);

*The date should be in this format:
“June 30, 2024 13:10:53”

19
Q

Code a single statement that displays the milliseconds that elapsed between the reference date and the beginning of 1980.

A

new Date(“January 1, 1980”).getTime();

20
Q

What does “d” mean?
var d = new Date(“January 31, 2023”).getTime();

A

d is the number of milliseconds from the reference date (Jan 1, 1970) through Jan 31, 2023.