Intro to JavaScript Flashcards

1
Q

What does it mean to declare a variable?

A

Tell the JavaScript engine that there exists a variable with a given name.

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

What does it mean to initialize a variable?

A

Tell the JavaScript engine that there exists a variable with a given name that will have an initial value defined by the code to the right of the assignment operator.

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

What does it mean to declare a function?

A

Tell the JavaScript engine what a function is named, what parameters can be passed in, what the function does then returns.

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

What types of data can be stored in a variable?

A

String, Number (Integers and Real/Decimal), Boolean (true/false), Objects, Functions

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

How is a date stored internally by the JavaScript engine?

A

As a real number (decimal) that represents the seconds since January 1, 1970. Left of the decimal represents whole seconds, and to the right of the decimal represents the fraction of the second.

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

What is a JavaScript engine?

A

The program that runs JavaScript in the browser

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

TRUE or FALSE: an array is an object?

A

TRUE. Arrays are special types of objects in JavaScript that have some special syntax. But normal object syntax applies as well. For example, you can declare an array with 
var array = [];
or with
var array = new Array();

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

What does null mean?

A

A value is explicitly not provided

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

What does undefined mean?

A

A value has not been defined

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

What is the difference between null and undefined?

A

null values do not exist, but are purposely set as not existing, while undefined values are simply unset to any value, including null.

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

What does NaN mean?

A

Not a NumberExamples would be 100/0 or sqrt(-1)

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

What “Truthy / Falsey”?

A

It is a way to evaluate conditions whereby a list of FALSE values is established and every other value is considered to be TRUE.

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

TRUE or FALSE: a variable can be changed from a string to a number in the middle of a program?

A

TRUE. Variables can be set using the assignment operator at any time in the program, and they can be set to any valid type with no limit on how many times the assignment can be performed.

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

What is the assignment operator?

A

=

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

What is the assignment operator in the context of a property of an object?

A

:

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

TRUE or FALSE: a function can be stored in a variable?

A

TRUE

17
Q

How would you initialize and then call a function that is stored in a variable?

A

var nameOfFunction = function(stringParam1, numberParam2, objectParam3) {
 return;
}

nameOfFunction(“something”, 2763.98, {
 stringProp1: “some value”,
 numberProp2: 27626
});

18
Q

TRUE or FALSE: functions need to be defined before they are used?

A

FALSE. Functions can be defined anywhere

19
Q

TRUE or FALSE: functions that are stored in variables need to be defined before they are used?

A

TRUE. This is like all variables. Variables must be declared before being referenced.

20
Q

How would one describe the following line of code:

var totalPrice = itemPrice * (1 + taxRate);

A

Store the product of the itemPrice and the quantity of one added to the taxRate in the totalPrice variable.

21
Q

How is the assignment variable processed?

A

Run the code on the right of the assignment variable, then store the result into the variable, constant or property on the left side.

22
Q

TRUE or FALSE: if a function has 3 parameters, you are required to pass in 3 parameters?

A

FALSE. Functions can have any number of parameters. Any parameters that do not have values passed in are set to null.

23
Q

How would you declare and then call a function with 3 parameters, passing in values to the first two parameters when called?

A

nameOfFunction(“value1”, 827); 

function nameOfFunction(stringParam1, numberParam2, objectParam3) {
 return;
}

24
Q

TRUE or FALSE: it doesn’t matter if a variable is declared as all lower case, you can reference the variable with capital letters too, so long as it is the same letter.

A

FALSE. Variables and functions are case sensitive, which means that the exact letters that are used to name the variable or function must be used to reference it. 

console.log is not the same as console.Log

25
Q

How do you declare an empty array?

A

var array = [];
or with
var array = new Array();

26
Q

How do you declare a date variable?

A

var now = new Date();

27
Q

How do you declare make an object that can be used with the new keyword?

A

The object must be declared as a function with it’s initial properties passed in as parameters, then set using the this keyword:

function CustomObject(stringParam1, booleanParam2) {
 this.stringProp1 = stringParam1;
 this.booleanProp2 = booleanParam2;
}

Then it can be treated like a normal object

var objectName = new CustomObject();
console.log(“object prop1”, objectName.stringProp1);

28
Q

How do you declare a simple object?

A

var objectName = {
 stringProp1 : “”,
 booleanProp2: false,
 numberProp3: 0.0,
 functionProp4: function(param1) {
 return param1;
 }
}

29
Q

Give an example of how to declare then initialize a variable to an empty string

A

var name = “”;

30
Q

What is the meaning of the character ;

A

Execute the code to the left (end of line)

31
Q

What is a compound condition?

A

A condition that has multiple statements that can be evaluated that are joined by && (AND) or || (OR)

32
Q

When expressions are evaluated in an if or else if statement, or in a boolean variable, how are they processed?

A

Compound conditions are processed left to right. Each statement is evaluated, starting with the left most statement, until a true statement is found. Remaining statements are ignored. If all statements are false, they are all executed.

33
Q

What is the name of the object populated by the browser’s JavaScript engine automatically that represents the HTML document itself?

A

document