Javascript Flashcards

1
Q

What is the purpose of variables?

A

to store date, to call upon the value 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

you would write the var then variable name , or identifier. If it has more than one name, it is written in camelCase
[var 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 would write the identifier then the variable value;

[name = 420;]

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, dollar sign($) or and underscore.

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

It needs to be written exactly how it is typed. meaning

thisVariable is not the same as thisvariable

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 give values that contain letters or other characters.

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 give a numerical value to a variable. Normally for it use as counting/mathematics.

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 define the var as a true/false value.

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 the assignment operator. it gives us the ability to assign a value to the variable.

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

you reassign the variable. you wont need to use the var to reassign the variable.

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

null is an intentionally nonexistent or invalid object, while undefined has no given value at all, or unintentional.

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

It helps identify what the value is related to, if there is no tag. It will just give out the string/value with no context.

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

a number value

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

What is string concatenation?

A

to join to variables into one.

var fullName = firstName + lastName;

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

It is used to add one value to another

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; true or false

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

It lets us add two values together, the result will then be assigned.

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

What are objects used for?

A

Objects are for RELATED data.

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

What are object properties?

A

A key value pair, a piece of data that is attached under an object with a unique name. The value may change, but the name will stay the same.

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

Describe object literal notation

A

You need { }, to store value, you need property name:(value)

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

use the delete

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

use dot notation or bracket notation.

dot
object.property = (new value);

bracket
object[‘property’] = (new value);

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

Describe array literal notation.

A

a variable will x amount of values separated by commas (usually in the same line)

you can store strings, numbers, and booleans

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

How are arrays different from “plain” objects?

A

arrays has data is relatable to one another, for example colors. Objects have relatable data to a certain object. (name, height, weight, occupation etc)

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

What number represents the first index of an array?

A

the first array value is INDEX 0 (zero)

It starts at zero because it the first item is zero index’s away from the BEGINNING of the array.

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

What is the length property of an array?

A

it will show how many Items are within each array.

for example:
var colors = [“white”, “black, “brown”, “green”]
has 4 items in. So:
numColors = colors.length;

should equal numColors = 4;

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

How do you calculate the last index of an array?

A

(# of items in array) - 1

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

Describe the parts of a function definition.

A
the [function] keyword
an optional name 
a comma-separated list of zero or more parameters.
start of the functions' code block'
the end of the function's code block
function example(parameter 1, parameter 2....)  {
 //....more javascript code...
 return;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Describe the parts of a function call.

A
function name 
comma separated list of zero or more arguments

sayHello ();

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

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

A

describing the function is creating the function and what it will do. Calling the function will practically “using” the function only.

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

What is the difference between a parameter and an argument?

A

parameter is a placeholder, it is variable that is unknown until we call the function.

A argument is the value that replaces the parameter value in the function.

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

Why are function parameters useful?

A

the parameters will let us change the value of the arguments when we call the function

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

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

A

Causes the function to produce a new value.

prevents any more code in the function’s code block from being run.

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

Why do we log things to the console?

A

to test out our code and to see if it runs properly.

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

What is a method?

A

a function which is a property of an object.

console.log is a method. it belongs to the object, console.

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

How is a method different from any other function?

A

a method is attached to a object.

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

How do you remove the last element from an array?

A

using the .pop() method

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

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

A

you use the Math.floor()

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

How do you generate a random number?

A

you use Math.random();

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

How do you append an element to an array?

A

.push() method.

42
Q

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

A

No, the return is not always useful in every situation.

43
Q

Give 6 examples of comparison operators.

A

==

<
>

44
Q

What data type do comparison expressions evaluate to?

A

boolean

45
Q

What is the purpose of an if statement?

A

to execute a statement if a certain statement is true

46
Q

Is else required in order to use an if statement?

A

no. it is not required

47
Q

Describe the syntax (structure) of an if statement.

A

It begins with if (conditions.) [

coding block}

48
Q

What are the three logical operators?

A

&& logical and
|| logical or
! logical not

49
Q

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

A

Logical and/or operators

!! &&

50
Q

when does the condition expression of a for loop get evaluated?

A

Before each loop iteration

51
Q

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

A

at the end of each loop iteration

52
Q

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

A

break

53
Q

What does the ++ increment operator do?

A

adds one to the variable

54
Q

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

A

‘focus’ event is fired

55
Q

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

A

‘blur’ event is fired

56
Q

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

A

‘input’ event is fired

57
Q

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

A

‘submit’ event is fired

58
Q

What does the event.preventDefault() method do?

A

this prevents the page from refreshing.

59
Q

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

A

it will refresh the page. because it will reset the form.

60
Q

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

A

elements

61
Q

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

A

the value property

example:
document.query(‘form’).name.value

this will get the value that is inputted in the ‘Name’ input.

62
Q

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

A

It will consist of a lot of bugs. so along the way it makes it easier to pinpoint what is exactly wrong.

63
Q

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

A

To check if all of your javascript codes/functions work properly and the output of those codes/functions are correct.

64
Q

What is the event.target?

A

the event target is the location where teh Event has started/fired from

65
Q

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

A

it will hide the element like it doesnt exist

66
Q

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

A

it takes a selector string as the argument.

element.matches(‘.selector’)

67
Q

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

A

using the getAttribute Method

element.getAttribute( )

68
Q

At what steps of the solution would it be helpful to log things to the console?

A

during conditional statements. to see if the function runs pass it.

69
Q

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

You would have to listen to eventListener tab

70
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

I would probably use hyperlinks. that would link certain elements to different pages. instead of manipulating the information.

71
Q

What is a method?

A

a function which is a property of an object. There are two kinds of methods;

instance methods which are build-in task performed instance or static mthods which are tasks that are called directyly on an objet constructor.

72
Q

How can you tell the difference between a method definition and a method call?

A

method definition includes the function () and what the method will do when it is called.

var doggo = {
     bork: function() {
         return 'bork! bork! bork!':
   }
}

method call is when the method is only attached to the object. such as

Object1.reverse( );

73
Q

Describe method definition syntax (structure).

A
var doggo = {
bork(method name): function() {
code block;
}
74
Q

Describe method call syntax (structure).

A

object.methodCall ();

75
Q

How is a method different from any other function?

A

methods are attached to objects and can be only used on the object that it is attached to.

76
Q

What is the defining characteristic of Object-Oriented Programming?

A

It is based on containing related data and the functions to objects. and the object is the only thing that can alter the object.

data and behavior is intertwined

77
Q

What are the four “principles” of Object-Oriented Programming?

A

1) Abstraction : removing physical, spatial, or temporal details.
2) Encapsulation : it is the bundling of data with the methods that operate on that data or restricting of direct access to some of an objects components.
3) Inheritance: is the mechanism of basing an object or class upon another object or
4) Polymorphism

78
Q

What is “abstraction”?

A

being able to work with complex things in simple ways.

79
Q

What does API stand for?

A

Application programming interface .

80
Q

What is the purpose of an API?

A

It is to give programmers a way to interact with a system in a simplified, consistent fashion. “abstraction”.

81
Q

What is this in JavaScript?

A

is an implicit parameter of all Javascript functions.

[this] is going to reference the object that it is currently in. if there is no reference to an object, [this] is referencing the window.

82
Q

What does it mean to say that this is an “implicit parameter”?

A

that it is available in a functions code block even though it was never included in the functions parameter list or declared with var

83
Q

When is the value of this determined in a function; call time or definition time?

A

it is determined at call time

84
Q

What does this refer to in the following code snippet?

var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};

2)Given the above character object, what is the result of the following code snippet? Why?

Given the above character object, what is the result of the following code snippet? Why?

A

character.greet is being called and it will return the firstName that it was assigned by using this.firstName.

this = the var character.

so this.firstName should return the string ‘Mario’

2) The result should be ‘It’s-a-me, Mario!’ because this.firstName is referencing to the objects (that this is placed in) firstName.

85
Q

How can you tell what the value of this will be for a particular function or method definition?

A

you can tell what [this] will be because it is attached to an object. so [this] is referring the object that it is contained in.

86
Q

How can you tell what the value of this is for a particular function or method call?

A

if you cannot see the function that is being called. you dont know what the value of [this] will be

87
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance.

88
Q

What is a prototype in JavaScript?

A

JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects

89
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?

A

you use Object.setPrototypeOf(Obj, prototype)

Object.setPrototypeOf(doggo, petPrototype);

90
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

it looks for the prototype that the object has inherited.

Object.setPrototypeOf(doggo, petPrototype)

so above, if doggo does not have a given method, it will look at petPrototype for that given method.

91
Q

What is a “callback” function?

A

it is a function that is passed into another function as an argument, which is then invoked inside the outer function to complete some kin of routine or action

92
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimerout( ) method.

it sets a timer which executes a function or specified piecoe of code once the timer expires.

It is a global method, so it can be called with no object to the left of it .

93
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval(function, code, [delay], [arguments after it ends] ) method

it repeatedly calls a function or executes a code snippet, with a fixed time delay between each call. it returns an interval ID with uniquely identifies the interval so you can remove it late by calling clearInterval( )

94
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

100 milliseconds

95
Q

What do setTimeout() and setInterval() return?

A

is a numeric, non zero value which identifies the timer created by the call to setInterval

96
Q

What is AJAX?

A

It is a technique for loading data into PART of a page without having to refresh the page. The data is often sent in a format called JavaScript Object Notation (or JSON)

97
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

98
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

XMLHttpRequest will work asynchronously unless stated otherwise.

99
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

the ‘load’ event is fired.

100
Q

Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

they are able to share teh same functionality because of prototype methods.

101
Q

What is Array.prototype.map useful for?

A

to manipulate the the array and create a new array with a function predicate. for example

multiplying all numbers of an array by 2
numbersArray.map(number => number * 2);

102
Q

What is Array.prototype.reduce useful for?

A

to combine values/objects in an array