Part 6- A Smarter Way to Learn JavaScript Flashcards
Code for converting a string that’s a number to its equivalent number
Number(variableName);
(the name of the variable is at the end)
Note: works for integer strings and floating-point number strings
Code for converting a number to a string?
variableName.toString();
(the name of the variable is at the beginning)
Limit the decimal places on a number?
varName.toFixed(# of digits);
HOWEVER this also converts it to a string
What is the code to get a new date object and assign it to the variable “now”?
var now = new Date();
*notice that “Date” is capitalized
In a Date object, what number is assigned to Sunday?
0
In a Date object, what number is assigned to Saturday?
6
In a Date object, what number is assigned to Thursday?
4
How would I extract the day of the week from a Date object called “party”?
party.getDay();
What’s the difference between these?
getDate();
getDay();
Date is day of the month
It’s indexed with 1
Day is the day of the week
It’s indexed with 0
What does getTime() return from a Date object??
The milliseconds since midnight, January 1, 1970
What does getMonth() return from a Date object??
A number. 0 for January, 1 for Feb etc. until December, which is 11
What’s the code that returns the year from a Date object “d”?
d.getFullYear();
What’s the code to return the smallest unit of time that JavaScript recognizes from a Date object “d”?
d.getMilliseconds()
Before you can getDate, getHours, or getFullYear, what must you do?
Get a Date object:
var d = new Date();
What is the code to return the hour from a Date object “d”?
d.getHours();
*Note that HOURS is plural. MINUTES, SECONDS, and MILLISECONDS