Part 7- A Smarter Way to Learn JavaScript Flashcards
Can you create a new Date object and pull a part of that object in the same statement?
Yes.
var d= new Date(“January 1, 1969”).getDay();
How do you modify one of the elements of a Date object?
Use “set” instead of “get”:
setHours() instead of getHours()
What is a function?
a block of code that executes whenever you invoke its name
How do you call a function?
nameOfFunction();
With functions, what’s the difference between a parameter and an argument?
Parameters are the names listed in the function declaration.
Arguments are the real values passed to (and received by) the function by a function call.
from W3 Schools:
Function parameters are listed inside the parentheses () in the function definition.
Function arguments are the values received by the function when it is invoked.
How do you code a function definition?
- keyword FUNCTION
- name of the function
- ()
- ;
Ex. function makeToast();
What makes a variable local?
If it is DECLARED in a function. Just using it in a function does not count– that will be be global.
Where are local variables used?
Only inside the function where they are declared.
Where are local variables understood?
Only inside the function where they are declared.
Where are global variables declared?
In the main code and not in a function.
Where are global variables understood?
Everywhere.
What is the syntax for the first line of a SWITCH statement?
switch(variable being tested) {
When would you use a SWITCH statement?
It’s a more elegant way to do an IF statement, especially if you have a lot of conditions.
What is the syntax for the second line of a SWITCH statement?
case (argument being tested) :
What does DEFAULT do in a SWITCH statement?
*The code that follows it executes if none of the conditions above it are met
*It works like an ELSE statement works in an IF…ELSE series
*same syntax as a CASE statement
*used at the end of the code block