JavaScript Flashcards
What is the purpose of variables?
Storing values
How do you declare a variable?
Using the var keyword
How do you initialize (assign a value to) a variable?
Var x = 89;
What characters are allowed in variable names?
Underscores, $. Numbers and letters
What does it mean to say that variable names are “case sensitive”?
The uppercase or lowercase letter refers to different values
What is the purpose of a string?
To store or manipulate text letters and sentences
What is the purpose of a number?
To store and manipulate numbers and decimals
What is the purpose of a boolean?
True or false for conditionals, loops
What does the = operator mean in JavaScript?
Assigning a value to a variables
How do you update the value of a variable?
Use the variable name and the equal sign and assign the value
What is the difference between null and undefined?
Null is an intentional no value, and undefined is not intentional
Why is it a good habit to include “labels” when you log values to the browser console?
For clarity to understanding what the console is working on, point of reference
Give five examples of JavaScript primitives.
String numbers boolean null undefined
What data type is returned by an arithmetic operation?
numeric, numbers
What is string concatenation?
adding strings together
What purpose(s) does the + plus operator serve in JavaScript?
Add numbers and concatenating strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adding to the value of the variables
What are objects used for?
Containers for keeping information
What are object properties?
The keys that give information about the object
Describe object literal notation.
{} property:value
How do you remove a property from an object?
delete keyword
What are the two ways to get or update the value of a property?
[] or dot notation
What are arrays used for?
to store multiple items
Describe array literal notation.
[] separated by “,”
How are arrays different from “plain” objects?
it can be indexed by numbers starting from 0
What number represents the first index of an array?
0
What is the length property of an array?
calculate the size of the array
How do you calculate the last index of an array?
length -1
What is a function in JavaScript?
A process that can be used and called to perform that same process.
Describe the parts of a function definition.
The name of the function, the function keyword, parameter list., code block, return statement.
Describe the parts of a function call.
Name of the function () arguments in the parenthesis.
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function calls require actual values, while function definitions require a name or variables, and function keyword.
What is the difference between a parameter and an argument?
Parameters are the name that is given o the piece of data that will give, later on, arguments are the actual values that are being passed on to the function.
Why are function parameters useful?
To be empty conatainers to hold values for the upcoming values
What two effects does a return statement have on the behavior of a function?
It makes the value of the function a value that is not undefined.
Why do we log things to the console?
Debugging and for clarity.
What is a method?
A function that is being stored as a property.
How is a method different from any other function?
A method must be attached and be called upon an object.
How do you remove the last element from an array?
array.pop()
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
Math.random() within the range of 0-1 non-inclusive
How do you delete an element from an array?
array.shift()-> from the begining;array.pop -> from the end; array.splice() froman arbitrary point till any point.
How do you append an element to an array?
srting.push()
How do you break a string up into an array?
string.split()
Do string methods change the original string? How would you check if you weren’t sure?
No, because strings are immutable-> log console and mdn.
Roughly how many string methods are there according to the MDN Web docs?
A lot.
Is the return value of a function or method useful in every situation?
No,
Roughly how many array methods are there according to the MDN Web docs?
A lot
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
> ,=,+===,!==
What data type do comparison expressions evaluate to?
boolean (true or false)
What is the purpose of an if statement?
Change the flow of the code, and make decisions.
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
If (condition){}
What are the three logical operators?
logical and, or, not
How do you compare two different expressions in the same condition?
&& or/and ||
What is the purpose of a loop?
To allow to do something multiple times
What is the purpose of a condition expression in a loop?
To put a stop to the loop
What does “iteration” mean in the context of loops?
Running of the for loop code block
When does the condition expression of a while loop get evaluated?
Beginning and after each iteration
When does the initialization expression of a for loop get evaluated?
In the beginning, and it only happens one time
When does the condition expression of a for loop get evaluated?
Before each iteration
When does the final expression of a for loop get evaluated?
After the code block
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
Increments the counter variable
How do you iterate through the keys of an object?
For in loop
What event is fired when a user places their cursor in a form control?
focus
What event is fired when a user’s cursor leaves a form control?
blur
What event is fired as a user changes the value of a form control?
input
What event is fired when a user clicks the “submit” button within a ?
submit
What does the event.preventDefault() method do?
prevent the default state from occurring
What does submitting a form without event.preventDefault() do?
delete the data
What property of a form element object contains all of the form’s controls.
.elements property
What property of form a control object gets and sets its value?
value property
What is one risk of writing a lot of code without checking to see if it works so far?
the code could be broken but you wouldn’t know where.
What is an advantage of having your console open when writing a JavaScript program?
visualize code and variables
What is a method?
A function of the object
How can you tell the difference between a method definition and a method call?
the function definition() block and call: name of the object. method name ().
Describe method definition syntax (structure).
Methods are functions attached to object,
Describe a method call syntax (structure).
object.methodname(arguments).
How is a method different from any other function?
that it acts on the object
What is the defining characteristic of Object-Oriented Programming?
Objects contain data and behavior.
What are the four “principles” of Object-Oriented Programming?
encapsulation, polymorphism, abstraction, inheritance
What is “abstraction”?
hiding irrelevant information
What does API stand for?
application programming interface
What is the purpose of an API?
allows the application to access data to communicate to the user and vice versa
What is* this* in JavaScript?
Object that the function is acting on
What does it mean to say that this is an “implicit parameter”?
it is actaully named and typed out
When is the value of this determined in a function; call time or definition time?
Call time
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); } };
Nothing at this point
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
It’s a me Mario!
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
It’s a-me undefined
How can you tell what the value of this will be for a particular function or method definition?
You can’t, as it hasn’t been called yet.
How can you tell what the value of this is for a particular function or method call?
Object to the left of the dot.