Javascript Flashcards

1
Q

What is the purpose of variables

A

To store data that you assign to it

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

How do you declare a variable?

A

Var

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

Using the assignment operator of =

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

What characters are allowed in variable name?

A

Name must begin with a letter, dollar sign, or underscore. CANNOT begin with a number.

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

That if a variable has the same name as another variable by one is capitalized, they are not considered the same

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 add text

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

For task that involve counting or calculating sums

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

Helpful when determining what steps are required next depending on what conditions are met

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

The variable’s values is being assigned to the variable’s name

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

Once you have declared that variable with the var keyword and assigned it a variable name and value, you only need to call the variable name and assign it a 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

Undefined means that a value was never assigned to the variable and null is essentially a placeholder for a value created by the developer. In null you can place values in, in undefined you cannot.

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

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

A

It helps you from getting confused when logging; it is a short string that describes the variable being logged

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

Give five examples of JavaScript primitives

A

String, number, boolean, undefined, and 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

Numbers

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

What is string concatenation?

A

When you combine strings together

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 perform arithmetic operations or to concatenate strings

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

Boolean

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

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

A

Adds a value to an existing variable and assigns the new value back to the same variable

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

What are objects used for?

A

They are used to group together a set of variables and methods

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

What are object properties?

A

Variables with a name and value

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

Describe object literal notation

A

IT is an array of (key:value) pairs that are are placed inside of curly brackets

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

How do you remove a property from an object?

A

by using the delete method nameofObject.property

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

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

A

Using period notation or square brackets

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

What are arrays used for?

A

To store a list of values

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

Describe array literal notation

A

You define a new array with empty square brackets

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

How are arrays different from “plain” objects?

A

Array are index objects are not

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

What kind of data types are array?

A

Reference data types

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

What is a function in JavaScript?

A

A set of statements that perform a task or calculates a value

It should take some input and return an output

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

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

A

When you call a function you are only using the name of the function and the parameter you want to put in it

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

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

A

Stops the function from running. Returns the function being called

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

What is the difference if you declare a variable outside vs inside a function?

A
  • If a variable is being defined within a function you can only use it in the function
    o If it is declared outside of the function that is fine because you can just give the function a new value in the function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Why do we log things to the console?

A

To constantly be informed on what our code is doing

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

what is a method?

A

Actions that can be performed on objects

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

How is a method different from any other function?

A

A method is associated with an object, while a function is not
A method is passed on the object it is called on

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

How do you remove the last element from an array?

A

Using the pop() method

36
Q

How do you round a number down to the nearest integer?

A

Math.floor()

37
Q

How do you generate a random number?

A

o Math.random()

38
Q

How do you delete an element from an array?

A

splice

39
Q

How do you append an element to an array?

A

By using .push() or shift()

40
Q

How do you break a string up into an array?

A

By using split

41
Q

Do string methods change the original string? How would you check if you weren’t sure?

A

No they are not able to change

42
Q

Is the return value of a function or method useful in every situation?

A

No because you might not want it returned

43
Q

Give 6 examples of comparison operators.

A

o <, > , >=, <=, !== , ===

44
Q

What data type do comparison expressions evaluate to?

A

Boolean to see if it is true or false

45
Q

What is the purpose of an if statement?

A

To guide a program to make decisions based on specific criteria

46
Q

Is else required in order to use an if statement?

A

It is not required you can just write if statements

47
Q

Describe the syntax (structure) of an if statement.

A

If (condition) { two sets of code for different outcomes}

48
Q

What are the three logical operators?

A

&&, ||, and !

49
Q

How do you compare two different expressions in the same condition?

A

By using &&, ||

50
Q

What is the purpose of a loop?

A

Repeats a sequence of instructions until a specific condition is met

51
Q

What is the purpose of a condition expression in a loop?

A

It test the condition each time the loop repeats

52
Q

When does the condition expression of a while loop get evaluated?

A

At the beginning of each iteration

53
Q

When does the initialization expression of a for loop get evaluated?

A

The very start of the loop

54
Q

When does the condition expression of a for loop get evaluated

A

It after the initialization and before every iteration

55
Q

When does the final expression of a for loop get evaluated?

A

At the end of the iteration

56
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

57
Q

How do you iterate through the keys of an object?

A

For … in loop

58
Q

What are the four components of “the Cascade”.

A

Source code, inheritance, specificity, and !important

59
Q

What does the term “source order” mean with respect to CSS?

A

The order that your CSS rules are written in your stylesheet

60
Q

How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?

A

Inherited properties which by default are set to the computed value of the parent element

61
Q

List the three selector types in order of increasing specificity.

A

No value, type, class, id

62
Q

Why is using !important considered bad practice?

A

It makes it difficult for other people to go in and make changes because they’ll have to be aware of what you put important on. It disrupts the natural flow in applying the css rules where properties are applied from top to bottom.

63
Q

What event is fired when a user places their cursor in a form control?

A

The ‘focus’ event

64
Q

What event is fired when a user’s cursor leaves a form control?

A

the ‘blur’ event

65
Q

What event is fired as a user changes the value of a form control?

A

The ‘input’ event

66
Q

What event is fired when a user clicks the “submit” button within a <form>?

A

The ‘submit’ event

67
Q

What does the event.preventDefault() method do?

A

o Cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur
o Will allow us to submit manually
o Prevents the default behavior

68
Q

What does submitting a form without event.preventDefault() do?

A

o The request that you inputted is submitting the form the request to the URL
o You might want to do more things to the data before actually sending a request

69
Q

What property of a form element object contains all of the form’s controls.

A

o The “elements” property
o .elements

70
Q

What property of a form control object gets and sets its value?

A

.value

71
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

If you do not catch the errors early one then the validity of the code after that mistake is in question

72
Q

What is an advantage of having your console open when writing a JavaScript program?

A

You can console log anything you wish to check into the console

73
Q

What is the event.target?

A

Whatever element that we are interacting with

74
Q

What is the affect of setting an element to display: none?

A

Removes whatever element that we currently on the screen

75
Q

What does the element.matches() method take as an argument and what does it return?

A

Matches compares the attribute as an argument with the attribute of whatever element you are comparing it to

76
Q

How can you retrieve the value of an element’s attribute?

A

o .getAttribute()

77
Q

What is JSON?

A

It is a text based format for representing structured data based on Javascript object syntax

78
Q

What are serialization and deserialization?

A

o Serialization is the process of turning an object in memory into a stream of bytes so you can send it over the network
 Turning it into a string
o Deserialization is the reverse process of turning a stream of bytes into an object in memory
 Back into an object

79
Q

Why are serialization and deserialization useful?

A

o Gives us a way to transmit data across different devices
o Clean way of being able to transmit data

80
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

o JSON.stringify()

81
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

o JSON.parse()

82
Q

How do you store data in localStorage?

A

localStorage.setItem(keyName, KeyValue)

83
Q

How do you retrieve data from localStorage?

A

localStorage.getItem()
pass in the keyName and it should return the value or null if the key does not exist

84
Q

What data type can localStorage save in the browser?

A

JSON string

85
Q

When does the ‘beforeunload’ event fire on the window object?

A

Before the page gets reloaded