JavaScript Fundamentals Flashcards

1
Q

What is a variable?

A

A container to store information or data

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

Why are variables useful?

A

Can reuse them, assign value to them

Readability

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

What two special characters can a variable begin with?

A

$

_

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

How do you declare a variable?

A

var variableName;

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

How do you assign a value to a variable?

A

Using the assignment operator (=)

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

Are variables case sensitive?

A

Yes

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

Which words cannot be used as variable names?

A

Any JS keywords

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

What is a string?

A

Form of data stored inside quotation marks

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

What is the string concatenation operator?

A

+

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

What is the difference when it comes to using single quotes or double quotes ( ‘ ‘ or “ “ )?

A

There is no difference, but must be consistent and use only one kind

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

How do you escape quotation characters?

A

\

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

What is type coercion?

A

Automatic conversion of values from one data type to another

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

What is a number in JavaScript?

A

Any number (integer and floating point)

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

What is an arithmetic operator?

A

Mathematical operators that can be used to calculate numbers

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

Name four of the arithmetic operators.

A
Addition
Subtraction
Division
Multiplication 
Increment 
Decrement 
Modulo
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the order of execution? (reference to mathematical operators)

A

Multiplication and division will come before addition and subtraction UNLESS you place addition and subtraction inside parentheses

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

What is a boolean?

A

Datatype of true or false

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

What is a comparison operator?

A

Compares two values and returns a boolean

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

What is the difference between undefined and null?

A

Undefined - absence of value

Null - intentional absence of value

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

What is a function?

A

Set of instructions to complete a task, reusable

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

Why are functions useful?

A

Reusable, don’t need to repeat yourself

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

How do you call a function?

A

functionName(arguments);

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

What are the parts of a function definition?

A
function functionName(parameters) {
// code block
 }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the difference between a parameter and an argument?

A

Parameter - variables when declaring a function

Argument - what you pass in when calling or invoking a function

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

Why is it important to understand truthy and falsy values?

A

To understand how they can be used in conditionals and how it will affect the result/return value

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

Why is the typeof null an object?

A

Bug in JavaScript creation

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

Why do you always use === for comparisons?

A

To make sure the values being compared in data type and value

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

Do all if statements require an else statement?

A

No

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

What is the proper syntax for using the or operator?

A

condition1 || (dual pipes) condition2

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

Why do you want to avoid using == for comparison?

A

Type coercion, don’t let JavaScript decide what type to make the value

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

What is the primary use case for switches?

A

Checks an expression against multiple cases, then executes the code of a matching case

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

Does the default case have to be at the bottom of the switch statement?

A

No

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

What happens if there is no break statement between cases?

A

The next case will be executed even if the evaluation does not match the case

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

What is an object in JavaScript?

A

Grouping mechanism

Collection of related data to store key:value pairs & methods

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

How do you create an object literal?

A
var objectName = {}
var objectName = new Object();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is a property in relation to JavaScript objects?

A

They are variables on an object

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

When should you use bracket notation over dot notation with objects?

A
  • The irregular property name (has spaces or starts with a number)
  • Subbing in a variable (with a string value) because dot notation doesn’t allow for substitution
38
Q

How do you remove a property from an object?

A

delete objectName.propertyName

* not super common

39
Q

What is an array in JavaScript?

A

Way to store data as lists

40
Q

How do you create an array literal?

A

[]

41
Q

What are the keys for the values inside an array?

A

Numbers starting at 0 indexing

42
Q

Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?

A

Objects - Array is a type of object

43
Q

What are some good use cases for using objects inside arrays?

A

If you have a collection of data on similar/related items that you want to store in a list

Ex. Items in a grocery store

var itemsSoldInStore = [ ]

{ 
name: apple,
price: 1,
inStock: true
 }
44
Q

What is the primary advantage to storing your selected elements in a variable?

A

Easier to access, more efficient, reusable

45
Q

Why might you need JavaScript to modify the DOM after the page loads?

A

Any user interaction with the webpage

Allows you to update the webpage in a more efficient way

46
Q

How can you better prepare when writing HTML for DOM manipulation in your JavaScript code?

A
Semantic HTML so easier to select elements
More intuitive or distinctive class names
*Easier to access the elements we are looking for
47
Q

What are the differences between innertext and textContent?

A

innerText - reads CSS rules, may be slower, may not be supported on all browsers, only shows “human-readable” text
textContent - ignores markup inside text element, gets text from ALL elements

48
Q

What datatype are the values you remove from a text input?

A

String

49
Q

Why is it so important to be able to dynamically update text?

A

If user interacts with websites, want to be able to show that a change happened

    • way to communicate with user
    • Dynamic website
50
Q

What are some of the drawbacks of HTML Event Handler Attributes?

A

Separate JS from HTML

51
Q

Why is the Window.event property useful for finding an element which was interacted with?

A

Can use the window.event.target property and other information to view what element was interacted with
Can access it this way

52
Q

Why is the Window.event property to be avoided in new code?

A

Not handled by all browsers

53
Q

Does a callback function require a name?

A

No, can be anonymous but most cases will have name

54
Q

What is the difference between the getElementById() method and the querySelector() method?

A

getElementById - can only get by ID

querySelector - can get any by type, like classes, elements, ids, and CSS selectors but less efficient

55
Q

Who passes in the event object into the handleClick callback function?

A

JavaScript

56
Q

What is the purpose of a loop?

A

While a condition is true, run this block of code,

redo multiple actions

57
Q

Why might there be different kinds of loops?

A

Based on whether you know how many times you need to loop through the code
for - variable trying to increment

58
Q

What is the purpose of a conditional expression as it relates to loops?

A

The loop will check to see if condition is true. If true, it will continue to run until condition is false.

59
Q

Could a loop potentially go on forever?

A

Yes, if condition is never false

60
Q

Could a loop never start?

A

Yes, if condition is never met or true

61
Q

How does a for loop differ from a while loop?

A

For loop - initialization, condition, and final-expression are all together (has an end)
While loop - will run until condition is false

62
Q

What potential use cases are there for for loops?

A

Looping through arrays and counting

63
Q

Which pieces of information provided in the parentheses for a for loop are mandatory?

A

None are

64
Q

What is a for in loop?

A

Variation of for loop, used to walk through object properties

65
Q

How do you target the value of a property in an object?

A

[ ] or dot notation

66
Q

When should you use a for in loop?

A

When you need to iterates over every property in an object

67
Q

What is the difference between the parentNode and parentElement properties?

A

Mostly the same except for when the parentNode is not element (ex. parentNode is the DOM = parentElement is null)

68
Q

Why is it important to be able to traverse the DOM?

A

If an item doesn’t have a class or ID, still need to be able to select it
Easier to access and see how elements are related
**To get to other elements based on what elements you’re currently on

69
Q

What kind of information is useful to store in custom attributes?

A

Can store information regarding the DOM

*hold data in regards to JavaScript

70
Q

What are two ways to target elements on the DOM?

A

querySelectorAll, getElementByID

71
Q

What is another way to add a text node to an element other than using textContent.

A

innerText (stripes whitespace), innerHTML(avoid using this)
**document.createTextNode(text)
BUT textContent is best to add text (95% of the time)

72
Q

How do you create a HTML element using vanilla Javascript?

A

document.createElement(elementName)

73
Q

Why is using loops and arrays for creating multiple dom elements preferable to creating them one at a time?

A

Keeps code DRY

74
Q

Why are arrays preferred over objects for the functionality referenced in question 1?

A

Because there are indexes and this sequence that will be the same order every time

75
Q

Why is it important to be able to retrieve and use data from inputs?

A

Handling user input

76
Q

Why is it dangerous to assume you have the correct data when creating elements?

A

People might try to hack your website

77
Q

How would you alter the game to make the choice from 1 - 500?

A

Math.floor(Math.random() * 500) + 1

78
Q

What are the disadvantages of inline styling via JavaScript?

A

Not separating our concerns

79
Q

What things do you have to consider when building a reset game function?

A
  • Clearing all the previous inputs

- Removing all added HTML classes (if any) or CSS styling

80
Q

What is event bubbling?

A

Event propagation starts at most specific then flows outward towards least specific (default)

81
Q

What is the difference between event.target and event.currentTarget.

A

event. currentTarget = target where event handler is attached
event. target = target that triggered the event handler

82
Q

What is the first argument the function setTimeout takes?

A

anonymous or callback function

83
Q

If the second argument is not passed into the setTimeout function, what is the default value?

A

0

84
Q

What are some scenarios where setTimeout can be useful?

A

When we want to change the look of something after a while

Modal pop up after inactivity

85
Q

What does the setInterval function return?

A

interval ID (number)

86
Q

What argument does the clearInterval function take?

A

ID returned by setInterval function

87
Q

What are some scenarios where setInterval can be useful?

A

Alternating between two images, colors

Timers

88
Q

What is the event loop?

A

Looks at call stack and looks at the event queue

If stack is empty, will push the event queue onto the callstack

89
Q

What does the term blocking mean?

A

slow code on the call stack that prevents code in task queue from running

90
Q

What is the call stack?

A

data structure (or mechanism) used to keep track of where in the program we are

91
Q

Which elements in a website are useful to create dynamically?

A

anything relies on outer source of data

92
Q

Why should you not create all elements dynamically?

A

Slow down code

**If you can create it with HTML, use HTML