JavaScript 0130 Flashcards

1
Q

What is the purpose of variables?

A

*To have a place to store data to be used later

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

How do you declare a variable?

A

using an assignment operator, e.g. “var”, and naming it within the confines of naming. it does not need to be initialized/assign to be declared

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

How do you initialize (assign a value to) a variable?

A

initialize is assign. use “=” and then assign its value

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

What characters are allowed in variable names?

A

$ _ letters numbers

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

What does it mean to say that variable names are “case sensitive”?

A

e.g. fullname and fullName are two different variables

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

What is the purpose of a string?

A

for text content

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

What is the purpose of a number?

A

store numbers to be used for things like calculation

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

What is the purpose of a boolean?

A

for decision making

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

What does the = operator mean in JavaScript?

A

it is used for declaring varables

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

How do you update the value of a variable?

A

type its name, then “=”, then the new value

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

What is the difference between null and undefined?

A

und var is not defined, null is like a placeholder

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

so you can distinguish them in the console

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

Give five examples of JavaScript primitives.

A

number, string, bulion, undefined, null

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

What data type is returned by an arithmetic operation?

A

a number

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

What is string concatenation?

A

joining data (strings?) with the + operator

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

What purpose(s) does the + plus operator serve in JavaScript?

A

to add numbers in calculations, to join data thru concatenation

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

What data type is returned by comparing two values (<, >, ===, etc)?

A

a boolean

18
Q

What does the += “plus-equals” operator do?

A

it adds

19
Q

What are objects used for?

A

for storing data with descriptions, or keys/objects

20
Q

What are object properties?

A

a variable becomes a property in an object

21
Q

Describe object literal notation.

A

you create an object by using “var”, e.g., “=”, then “{“, so:

var person = {name: colin, hobby: cycling}

22
Q

How do you remove a property from an object?

A

use the delete keyword, e.g. “delete person.name”

23
Q

What are the two ways to get or update the value of a property? (give two examples of updating and two of getting)

A

bracket and dot notation, e.g.:

console.log(person.name)
console.log(person[name])

person.name = “colin”
person[“name”] = “colin”

24
Q

what’s another word for “property” in objects?

A

a property can be called a key, and with a value is called a “key value pair”

25
Q

when is bracket notation better?

A

when dealing with invalid variable names

26
Q

What are arrays used for?

A
27
Q

Describe array literal notation.

A
28
Q

How are arrays different from “plain” objects?

A

they are indexed numerically?

29
Q

What number represents the first index of an array?

A

zero

30
Q

What is the length property of an array?

A

(.length) tells us how long an array is

31
Q

How do you calculate the last index of an array?

A

.length - 1

32
Q

what is a word for “[ ]”?

A

in arrays, the brackets “[ ]” can be thought of as “at”

33
Q

what are the parts of a function’s syntax?

// [1] [2] [3]
function example(parameter1, parameter2, parameter3, …) { // [4]
// …more JavaScript code…
// [5]
return;
} // [6]

A

The function keyword to begin the creation of a new function.
An optional name. (Our function’s name is sayHello.)
A comma-separated list of zero or more parameters, surrounded by () parentheses. (Our sayHello function doesn’t have any parameters.)
The start of the function’s code block, as indicated by an { opening curly brace.
An optional return statement. (Our sayHello function doesn’t have a return statement.)
The end of the function’s code block, as indicated by a } closing curly brace.

34
Q

What is a function in JavaScript?

A

a block of lines of code which can be called to perform actions

35
Q

Describe the parts of a function definition.

A
36
Q

Describe the parts of a function call.

A

name of function and parentheses

37
Q

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

skip?

38
Q

What is the difference between a parameter and an argument?

A

parameter like placeholder
argument is what goes in placeholder

39
Q

Why are function parameters useful?

A

giving the function what it needs to run

40
Q

What two effects does a return statement have on the behavior of a function?

A

stops the code from running, and tells computer what to return