Part 7- A Smarter Way to Learn JavaScript Flashcards

1
Q

Can you create a new Date object and pull a part of that object in the same statement?

A

Yes.
var d= new Date(“January 1, 1969”).getDay();

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

How do you modify one of the elements of a Date object?

A

Use “set” instead of “get”:
setHours() instead of getHours()

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

What is a function?

A

a block of code that executes whenever you invoke its name

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

How do you call a function?

A

nameOfFunction();

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

With functions, what’s the difference between a parameter and an argument?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you code a function definition?

A
  1. keyword FUNCTION
  2. name of the function
  3. ()
  4. ;

Ex. function makeToast();

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

What makes a variable local?

A

If it is DECLARED in a function. Just using it in a function does not count– that will be be global.

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

Where are local variables used?

A

Only inside the function where they are declared.

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

Where are local variables understood?

A

Only inside the function where they are declared.

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

Where are global variables declared?

A

In the main code and not in a function.

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

Where are global variables understood?

A

Everywhere.

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

What is the syntax for the first line of a SWITCH statement?

A

switch(variable being tested) {

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

When would you use a SWITCH statement?

A

It’s a more elegant way to do an IF statement, especially if you have a lot of conditions.

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

What is the syntax for the second line of a SWITCH statement?

A

case (argument being tested) :

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

What does DEFAULT do in a SWITCH statement?

A

*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

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

In a SWITCH statement, is the DEFAULT line optional?

A

*Yes, just as else code is optional after an if
statement.

*Without the default code, if none of the cases test true, nothing happens.

*However, careful coders include a break statement after the last
condition anyway as insurance, even though it may be superfluous. If you decide to add a new
condition to the end later, you won’t have to remember to add a break to the block above it in
order to avoid a disastrous cascade of statements.

17
Q

When should you use a FOR loop as opposed to a WHILE loop?

A

*FOR loop: you know how many times the loop should run.

*WHILE loop: you want the loop to break based on a condition other than the number of times it runs

18
Q

How do you code a WHILE loop?

A
19
Q

How can you crash the browser using a WHILE loop?

A

If you don’t increase the variable used in the condition, the loop will never end. This will crash your browser.

20
Q

What the difference in how these execute? (Code is incomplete– I’m only showing the parts of a loop that change):

var i = 0;
(i < 5)
i++

var i = 5;
(i > 0);
i–

A

There is no difference in the effect, but one subtracts on each loop and the other adds on each loop.