javascript Flashcards
What is the purpose of variables?
to store data for the future
How do you declare a variable?
use a variable keyword to declare the variable then a variable name
“var poopy”
How do you initialize (assign a value to) a variable?
use a =
What characters are allowed in variable names?
letters, underscores, $, numbers can be used but NOT in the front
Numbered variable names are CRINGE
What does it mean to say that variable names are “case sensitive”?
Score =/= score
What is the purpose of a string?
way to hold a sequence of characters - preserve text without freaking js out
What is the purpose of a number?
calculations, MATHS
What is the purpose of a boolean?
use it to make a choice
What does the = operator mean in JavaScript?
to assign variables things
How do you update the value of a variable?
var name then assign it to another variable, no keyword
What is the difference between null and undefined?
null - intentional absence of a value - it can be defined
undefined - bad - empty that comes from JS. it says “theres nothing here” - means you fucked up
Why is it a good habit to include “labels” when you log values to the browser console?
otherwise you don’t know what the console log is for
Give five examples of JavaScript primitives
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
taking any type of values. that get added to a string, and it all becomes a string.
What purpose(s) does the + plus operator serve in JavaScript?
math and concatenate
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
they dbz fusion into gotenks
What are objects used for?
group together variables/properties
what if i need info on more than 1 dog???
What are object properties?
key + value inside the object
the word & the definition in the dictionary
Describe object literal notation.
an array of key:value pairs with a comma inbetween, except for the last
How do you remove a property from an object?
delete operator
What are the two ways to get or update the value of a property?
brackets or dot for get, same for update
What are arrays used for?
good for lists of stuff at any length
the order is either EXTREMELY important, or doesn’t matter
Describe array literal notation.
brackets baybee with any data type inside
How are arrays different from “plain” objects?
all arrays have a length property, even []
What number represents the first index of an array?
0, big fat zero
What is the length property of an array?
how long the array is
How do you calculate the last index of an array?
array.length minus 1
What is a function in JavaScript?
a set of stuff that performs a task
Describe the parts of a function definition.
inputs outputs rules, (), {}, function name, parameters, keywords, etc etc etc
var const let for while do
Describe the parts of a function call.
arguments parameters function name
When comparing them side-by-side, what are the differences between a function call and a function definition?
define makes the function call runs it, calls have no {}
What is the difference between a parameter and an argument?
arguments are values provided when function is called
parameters are placeholder names for when function is defined
Why are function parameters useful?
its a placeholder and kinda a formula for later
What two effects does a return statement have on the behavior of a function?
Give 6 examples of comparison operators.
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
it allows us to make conditions
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (conditon) {stuff happens}
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
&&, ||
Why do we log things to the console?
to see wtf is happening, debugging
What is a method?
actions performed on objects
How is a method different from any other function?
methods are associated with objects
functions are NOT
How do you remove the last element from an array?
object.pop()
pop method
How do you round a number down to the nearest integer?
math.floor()
How do you generate a random number?
math.random()
random method of the math object
it gives you 0 - .999999999999999999, then u multiply by whatev u need to get the rando # u need
How do you delete an element from an array?
splice method
How do you append an element to an array?
push
generally we add things to ends of arrays
How do you break a string up into an array?
split
Do string methods change the original string? How would you check if you weren’t sure?
console log it
yes
Is the return value of a function or method useful in every situation?
naw
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?
allows you t odo the same t’hing over and over wtihout having to write a lot of code.
repeat same codeblock over and over until a condition is met
What is the purpose of a condition expression in a loop?
the condition is the breaks. How do we stop the loop?
What does “iteration” mean in the context of loops?
every single pass thru of the loop code block
When does the condition expression of a while loop get evaluated?
before executing the iteration/codeblock
When does the initialization expression of a for loop get evaluated?
it happens once, before anything.
When does the condition expression of a for loop get evaluated?
after initialization, and every time it repeats (before iterations)
When does the final expression of a for loop get evaluated?
end of each loop iteration
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break - good for if you’re tryna find 1 value in an array or something
What does the ++ increment operator do?
How do you iterate through the keys of an object?
for key in object
What is JSON?
text based data format
What are serialization and deserialization?
converts object into string
deserial converts string into object
Why are serialization and deserialization useful?
How do you serialize a data structure into a JSON string using JavaScript?
json dot parse
How do you deserialize a JSON string into a data structure using JavaScript?
What is a method?
a function which is a property of an object
How can you tell the difference between a method definition and a method call?
has the codeblock, call does not
Describe method definition syntax (structure).
objects property: (function parameters) {codeblock}
Describe method call syntax (structure).
object.method (arguments)
How is a method different from any other function?
it’s defined in an object, there’s object . _____
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods)
What are the four “principles” of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
What is “abstraction”?
being able to work with complex systems, but in simple ways
What does API stand for?
application programming interface
What is the purpose of an API?
a way for 2 or more computers to interact with each other
What is this in JavaScript?
the value of this is determined by how a function is called (runtime binding). It can’t be set by assignment during execution, and it may be different each time the function is called.
What does it mean to say that this is an “implicit parameter”?
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?
How can you tell what the value of this is for a particular function or method call?
How can you tell what the value of this is for a particular function or method call?