JavaScript Flashcards
What is the purpose of variables?
helps store data to remember
How do you declare a variable?
var declares/makes the variable
How do you initialize (assign a value to) a variable?
you assign it with a = sign.
What characters are allowed in variable names?
letters, $, underscore, and numbers(can be used as long as it’s not the first character)
What does it mean to say that variable names are “case sensitive”?
if you accidentally capitalize a letter it is a WHOLE DIFFERENT VARIABLE.
What is the purpose of a string?
it’s a way to hold a sequence of variables
What is the purpose of a number?
to do math
What is the purpose of a boolean?
a true or false statement
What does the = operator mean in JavaScript?
an assignment
How do you update the value of a variable?
no keyword is necessary (something = ‘something’)
What is the difference between null and undefined?
null is a value that can only be assigned. undefined can come from many different things.
Why is it a good habit to include “labels” when you log values to the browser console?
if you console.log without a label you don’t know what it really is.
Give five examples of JavaScript primitives.
string, number, undefined, null, and boolean.
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
adding strings together to make a bigger string
What purpose(s) does the + plus operator serve in Javascript?
addition or concateanation.
What data type is returned by comparing the two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the variable
What are objects used for?
They group together a set of variables and functions.
What are object properties?
variables that are apart of an object.
Describe object literal notation.
{
something: value,
something2: value2,
}
How do you remove a property from an object?
You use the keyword delete and then use dot notation to identify the property or method you want to get rid of.
What are the two ways to get or update the value of a property?
var varName = object.property/method name
OR
object.propertyname = “property value”
What are arrays used for?
good for rendering lists of data that are important or not important.
Describe array literal notation.
variable followed by a name followed by bracket notation followed by strings, or a list of items.
How are arrays different from “plain” objects?
Arrays are a special type of variable that is also mutable and can also be used to store a list of values.
What number represents the first index of an array?
0
What is the length property of an array?
it tells you how many properties you have in the array
How do you calculate the last index of an array?
you subtract the length of the array by one and then assign it to a new variable.
What is a function in Javascript?
a chunk of code that returns something.
Describe the parts of a function definition.
- function keyword. 2. optional name. 3. a list of parameters.
- opening curly brace. 5. optional return. 6. closing curly brace.
Describe the parts of a function call.
When comparing them side-by-side, what are the differences between a function call and a function definition?
What is the difference between a parameter and an argument?
putting things in the ()
Why are function parameters useful?
They allow for the function to take in values. if they weren’t there. functions would do the same thing over and over again.
What two effects does a return statement have on the behavior of a function?
return spits out a value that the rest of the coed can use. Anything under the return statement WILL NOT RUN.
Give 6 examples of comparison operators.
==, !=, ===, !==, >, >=, <, <=
What data type do comparison expressions evaluate too?
What is the purpose of an if statement?
to provide an output of true or false.
Is else required in order to use an if statement?
no.
Describe the syntax (structure) of an if statement.
What are three logical operators?
logical and, logical or, logical not. &&, ||, !
How do you compare two different expressions in the same condition?
Why do we log things in the console?
to debug certain parts of our code.
What is a method?
a method is a function which is a property of an object. a method could also be considered an object reference to a function.
How is a method different from any other function?
methods are attributed to an object.
How do you remove the last element from an array?
.pop() method
How do you round a number down to the nearest integer?
Math.floor() method
How do you generate a random number?
Math.random() method.
How do you delete an element from an array?
.splice() method
How do you append an element to an array?
.push() method
How do you break a string up into an array?
.split() method
Do string methods change the original string? How would you check if you weren’t sure?
it doesn’t change the string and you can console.log it.
Is the return value of a function or method useful in every situation?
no.
What three-letter-acronym should you always include in your Google search about a Javascript method or CSS property?
MDN
What is the purpose of a loop?
it is a way for a function code block to keep running until it meets it requirements
What is the purpose of a condition expression in a loop?
it’s what stops the loop from running infinitely.
What does “iteration” mean in the context of loops?
iteration is the amount of times that the loop runs.
When does the condition expression of a while loop get evaluated?
before each iteration.
When does the initialization expression of a for loop get evaluated?
only in the beginning and it gets checked just once.
When does the condition expression of a for loop get evaluated?
it happens after the initialization and then checks the condition every time before it runs the code block
When does the final expression of a for loop get evaluated?
after each iteration.
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?
it increases the value by 1.
How do you iterate through the keys of an object?
What is JSON?
What are serialization and deserialization?
converts our object into a string and deserialization is the opposite of it.
Why serialization and deserialization useful?
serialization is easy to store data for later. deserialization is easy to organize and reuse data.
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
How do you deserialize a JSON string into a data structure using Javascript?
How do you store data in localStorage?
How do you retrieve data from localStorage?
What data type can localStorage save in the browser?
When does the ‘beforeunload’ event fire on the window object?
What is a method?
A method is a function which is a property of an object.
How can you tell the difference between a method definition and a method call?
the method definition consists of a method header and method body while the method call method.name();
Describe method definition syntax (structure).
property: function () {
method body;
};
Describe method call syntax (structure).
method.name(arguements);
How is a method different from any other function?
the method had to be associated with an object while a function isn’t.
What is the defining characteristic of Object-Oriented Programming?
Encapsulation. (all important information is contained inside an object and only select information is exposed.
What are the four “principles” of Object-Oriented Programming?
Abstraction, encapsulation, polymorphism, and inheritance.
What is “abstraction”?
hiding all but the relevant data about an object in order to reduce complexity and increase efficiency.
What does API stand for?
Application programming interface.
What is the purpose of an API?
API is a way for two or more computers to communicate with each other.
What is .this in javascript?
refers to an object, and depends on how it’s being invoked(used or called). it refers to different objects when being used.
What does it mean to say that this is an “implicit parameter”?
it is available in the functions code block even though it was never included in the function’s parameter list or declared with var.
When is the value of this determined in a function; call time or definition time?
call time.
How can you tell what the value of this will be for a particular function or method definition?
can only know if it’s being called.
How can you tell what the value of this is for a particular function or method call?
what object is left to the dot. otherwise it is just window.
What kind of inheritance does the JavaScript programming language use?
prototype
What is a prototype in JavaScript?
object that shares data
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?
it’s within the prototype method.
If an object does not have its own property or method by a given key, where does JavaScript look for it?
prototype.
What does the new operator do?
the new operator makes a blank javascript object from scratch it then takes the value of the prototype property and it makes it equal to the __prototype operator. the return is the new object if there is one.
What property of JavaScript functions can store shared behavior for instances created with new?
What does the instanceof operator do?
the instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.
What is a “callback” function?
a function that is passed into another function as an argument.
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?
you can use setTimeout()
How can you setup a function to be called repeatedly without using a loop?
setInterval()
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
What setTimeout() and setInterval() return?