Javascript Flashcards
What is the purpose of variables?
Used to hold data for scripting
How do you declare a variable?
Use the keyword var then the name you want to give to the variable
How do you initialize (assign a value to) a variable?
with the “=” sign.
What characters are allowed in variable names?
letters, numbers, _, $
What does it mean to say that variable names are “case sensitive”?
var Apple is different then var apple
What is the purpose of a string?
Strings hold information in text form.
What is the purpose of a number?
numbers hold information in numerical form.
Used for math
What is the purpose of a boolean?
to declare if something is true or false. Used for conditionals
Allow us to make decisions in code.
What does the = operator mean in JavaScript?
Is being assigned to
How do you update the value of a variable?
write the name of the variable with a different value
What is the difference between null and undefined?
null is purposeful emptiness. (declared by developer)
undefined is accidental emptiness. (declared by javascript)
Why is it a good habit to include “labels” when you log values to the browser console?
Helps with debugging.
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
To join 2 or more strings together.
What purpose(s) does the + plus operator serve in JavaScript?
can be used for arithmetic expressions and also string concatenation.
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the value and assigns that result to original value.
ex: x+=y // x = x + y
What are objects used for?
to store data with multiple properties(pieces of data) in a variable.
What are object properties?
individual piece of named data within an object.
Describe object literal notation.
declare the variable name it, “{
and key: value,
key: value,
};
object, key, value
How do you remove a property from an object?
use the delete keyword followed by the object name and property name
delete object.property;
What are the two ways to get or update the value of a property?
object.property = ‘updated value’
object[‘property’] = ‘updated value’
dot notation and square bracket notation.
What are arrays used for?
It is used to store a list of information/values.
Describe array literal notation.
array = [ ‘one’, ‘two’, ‘three’];
How are arrays different from “plain” objects?
Values of an array are almost always the exact same data type.
Has a length property as default.
What number represents the first index of an array?
[0]
What is the length property of an array?
shows total number of values are in the array.
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
A process or set of actions with a name that can be reused within your code.
Describe the parts of a function definition.
(function keyword) ->function nameOfFunction(parameter) {
function block
ends with return statement
};
Describe the parts of a function call.
nameOfFunction(argument); <– argument is optional depending.
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definitions include a function keyword and code block.
What is the difference between a parameter and an argument?
parameter is used as a placeholder to define function, argument is the actual value used when you call it.
Why are function parameters useful?
It gives you the ability to apply the function to many different things without writing a different function.
What two effects does a return statement have on the behavior of a function?
- return causes the function to produce a value.
- Prevents any more code in the function code block from running.
Why do we log things to the console?
To help with troubleshooting, to check your code.
What is a method?
It is a function stored as a property of an object.
How is a method different from any other function?
It has a dot notation.
How do you remove the last element from an array?
Using the 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
splice(start, delete)
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?
They do not, use console.log method on original string to verify
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
Give 6 examples of comparison operators.
< > <= >= != == === !==
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
Evaluate a condition to return a boolean and run instructions based on the boolean.
It allows us to make decisions in our code.
Is else statement required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if {
is true {
do this
}
}
What are the three logical operators?
“&& || ! (and, or, not)”
How do you compare two different expressions in the same condition?
“use && ||”
What is the purpose of a loop?
Loops allow an easy way to do something over and over.
What is the purpose of a condition expression in a loop?
Condition’s ultimate goal is to check if the loop should move forward.
Ultimate goal is to stop the loop.
What does “iteration” mean in the context of loops?
A single repetition of the code block.
When does the condition expression of a while loop get evaluated?
Evaluated before each loop iteration. (iteration of the code block)
When does the initialization expression of a for loop get evaluated?
Declared before the loop begins. Only runs one time.
When does the condition expression of a for loop get evaluated?
Evaluated before each loop iteration.
When does the final expression of a for loop get evaluated?
After each iteration and before the condition
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?
adds +1 to the value permanently.
How do you iterate through the keys of an object?
Use for for in loop.