JavaScript Flashcards

1
Q

What is the purpose of variables?

A

A variable is a way to store values.

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

How do you declare a variable?

A

Use the reserved keyword var to declare a variable in JavaScript. Syntax: var ; var = ; A variable must have a unique name.

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

You can assign a value to a variable using the = operator when you declare it or after the declaration and before accessing it

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

Start them with a letter, underscore _, or dollar sign $.
After the first letter, you can use numbers, as well as letters, underscores, or dollar signs.
Don’t use any of JavaScript’s reserved keywords.

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

means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

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

to represent text rather than numbers

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

to represent and manipulate numbers

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

to create true/false statements

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

assigns a value to its left operand based on the value of its right operand.

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

undefined is a type, whereas null an object

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

Give five examples of JavaScript primitives.

A

undefined , null , boolean , string and number

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

What data type is returned by an arithmetic operation?

A

numeric data

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

What is string concatenation?

A

Concatenation is the process of appending one string to the end of another string

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

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

A

precedes its operand and evaluates to its operand but attempts to convert it into a number, if it isn’t already

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

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

A

boolean

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

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

A

adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left.

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

What is object used for?

A

An object is an abstract data type with the addition of polymorphism and inheritance.

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

What are object properties?

A

Object properties are defined as a simple association between name and value

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

Describe object literal notation.

A

The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array

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

How do you remove a property from an object?

A

delete operator

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

What are the two ways to get or update the value of a property?

A

dot notation and square brackets

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

What are arrays used for?

A

to store a collection of data

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

Describe array literal notation.

A

array literal notation is where you define a new array using just empty brackets.

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

How are arrays different from “plain” objects?

A

object store different types of data, dont have orders. array store same types of data, have orders.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What number represents the first index of an array?
0
26
What is the length property of an array?
how many pieces in the array
27
How do you calculate the last index of an array?
array.length-1
28
What is a function in JavaScript?
a set of statements that performs a task or calculates a value
29
Describe the parts of a function definition.
A function has three parts, a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements of the set of outputs in such a way that each input is assigned exactly one output.
30
Describe the parts of a function call.
Function calls contain the name of the function being executed followed by a list of values, called arguments, which are assigned to the parameters in the function definition
31
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function is a piece of code which enhanced the reusability and modularity of your program. It means that piece of code need not be written again. A function call means invoking or calling that function. Unless a function is called there is no use of that function.
32
What is the difference between a parameter and an argument?
The values that are declared within a function when the function is called are known as an argument. Whereas, the variables that are defined when the function is declared are known as a parameter.
33
Why are function parameters useful?
Parameters allow us to pass information or instructions into functions and procedures .
34
What two effects does a return statement have on the behavior of a function?
A return statement ends the execution of a function, and returns control to the calling function.
35
Why do we log things to the console?
console. log specifically is a method for developers to write code to inconspicuously inform the developers what the code is doing
36
What is a method?
A JavaScript method is a property of an object that contains a function definition.
37
How is a method different from any other function?
a method is associated with an object, while a function is not
38
How do you remove the last element from an array?
pop()
39
How do you round a number down to the nearest integer?
floor()
40
How do you generate a random number?
random()
41
How do you delete an element from an array?
splice()
42
How do you append an element to an array?
push() to the end; unshift() to the beginning
43
How do you break a string up into an array?
split()
44
Do string methods change the original string? How would you check if you weren't sure?
no, console.log origin string out
45
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property
MDN
46
Give 6 examples of comparison operators
>,=,<=,!=,===
47
What data type do comparison expressions evaluate to?
bolean
48
What is the purpose of an if statement?
The IF statement is a decision-making statement that guides a program to make decisions based on specified criteria
49
Is else required in order to use an if statement?
else is compulsory to use with if statement.
50
What are the three logical operators?
and , or, not
51
How do you compare two different expressions in the same condition?
and or or
52
What is the purpose of a loop?
Loops allow you to repeat a process over and over without having to write the same (potentially long) instructions each time you want your program to perform a task.
53
What is the purpose of a condition expression in a loop?
tell loop when to stop
54
What does "iteration" mean in the context of loops?
Iteration is the repetition of a process in a computer program, usually done with the help of loops.
55
When does the condition expression of a while loop get evaluated?
before executing the statement.
56
When does the initialization expression of a for loop get evaluated?
before the loop begin
57
When does the condition expression of a for loop get evaluated?
at the end of each loop iteration
58
When does the final expression of a for loop get evaluated?
at the end of the loop iteration
59
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
60
How do you iterate through the keys of an object?
for in loop
61
What is the className property of element objects
to set or return the value of an element's class attribute
62
How do you update the CSS class attribute of an element using JavaScript
use queryselector to select the query then use className to change
63
What is the textContent property of element objects?
The textContent property returns: The text content of the element and all descendaces, with spacing and CSS hidden text, but without tags
64
How do you update the text within an element using JavaScript?
use queryselector to select the query then use textContent to change
65
What is a client?
a desktop computer or workstation that is capable of obtaining information and applications from a server.
66
what is a server
a server is a piece of computer hardware or software that provides functionality for other programs or devices, A server stores, sends, and receives data