JavaScript Flashcards
What is the purpose of variables?
to store data
How do you declare a variable?
you the keyword var and then the variable name
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
letters, numbers, underscore, $
What does it mean to say that variable names are “case sensitive”?
upper case letters and lower case letters are different
What is the purpose of a string?
to hold a list of characters
What is the purpose of a number?
they are for math
What is the purpose of a boolean?
to return the value true or false
What does the = operator mean in JavaScript?
its an assignment operator
How do you update the value of a variable?
you put the variable name and = then the new value
What is the difference between null and undefined?
null means the variable has no value and undefined refers to a value that is empty or doesn’t exist
Why is it a good habit to include “labels” when you log values to the browser console?
to show what is being used
Give five examples of JavaScript primitives.
number, undefined, string, boolean, null
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
When two or more strings are joined together to create one new string
What purpose(s) does the + plus operator serve in JavaScript?
It adds numbers together or concatenates strings
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Adds the value on the right to the variable on the left and then assigns that to the left variable
What are objects used for?
Grouping together a set of variables and functions to create a model of something you would recognize from the real world.
What are object properties?
A variable within an object.
Describe object literal notation.
declare the variable and name it then use curly brace and make property and value
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
dot notation and bracket notation
What are arrays used for?
Storing multiple pieces of data
Describe array literal notation.
Create an array and give it a name and then assign values inside of a bracket
How are arrays different from “plain” objects?
arrays are used for lists and arrays are used for the same data type
What number represents the first index of an array?
0
What is the length property of an array?
arrayname.length
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
A set of statements that perform a task
Describe the parts of a function definition.
Function keyword, parameters in parentheses, statement enclose in curly braces
Describe the parts of a function call.
function keyword and argument in parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call calls the function while the function definition determines what the function does
What is the difference between a parameter and an argument?
a parameter is used in a function definition, while an argument is used on a function call.
Why are function parameters useful?
It determines what is to be used as an argument for the function
What two effects does a return statement have on the behavior of a function?
it stops the function and returns whatever is after the return keyword
Why do we log things to the console?
So we can see what the output of something would be.
What is a method?
A method is a function which is a property of an object
How is a method different from any other function?
A method is an object property that has a function value, meanwhile a function is a block of code designed to perform a particular task.
How do you remove the last element from an array?
you use the .pop() method