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.