JavaScript Flashcards
What is the purpose of variables?
They allow us to store values or data to use for functions and other things
How do you declare a variable?
Var variableName = value, need var
How do you initialize (assign a value to) a variable?
Set the variable = to a value with the assignment operator
What characters are allowed in variable names?
Letters, $, _ and numbers, but they can’t start with a number
What does it mean to say that variable names are “case sensitive”?
Varname is a different variable than varname
What is the purpose of a string?
To store and interact with text content
What is the purpose of a number?
To store and interact with numbers
What is the purpose of a boolean?
To store and interact with boolean values. Often used as a switch or to make decisions
What does the = operator mean in JavaScript?
It means ‘assigned the value of’
How do you update the value of a variable?
You reassign it a new value
What is the difference between null and undefined?
Null is an object with no value, undefined has no value or type.
Undefined comes from javascript engine, it helps js tell us if something isn’t there, null has to be defined by the human.
Why is it a good habit to include “labels” when you log values to the browser console?
To know what you are logging
Give five examples of JavaScript primitives.
String, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
A number
What is string concatenation?
It is when you use the + symbol to add two strings together, called concatenation
What purpose(s) does the + plus operator serve in JavaScript?
It can and numbers and concatenate strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
It adds the value with the variable and assigns that value to the variable
What is an expression
It is a chuck of code in JS.
What are objects used for?
Used to store related data of all different data types (variables and functions)
What are object properties?
They are the individual data types within an object literal
Describe object literal notation.
Object literal notation declares a variable as an object with the assignment operator with the property, value pairs within curly brackets separated by commas.
How do you remove a property from an object?
Use the delete key word and then the property you want to delete in dot notation
What are the two ways to get or update the value of a property?
Dot notation, or bracket notation
What are arrays used for?
To store lists of data, generally better for large sums of data
Describe array literal notation.
Var arrayName = [‘index1’, ‘index2’, ‘index3’]
How are arrays different from “plain” objects?
They have index numbers paired with each value instead of property, arrays have a set order, objects don’t have a set order
What number represents the first index of an array?
0
What is the length property of an array?
The length property of an array is the number of index values in the array
How do you calculate the last index of an array?
You can use the length property to find the length of the array, and then subtract that number by one since the first index is 0.
lastIndex = array.length - 1;
What is a function in JavaScript?
Is a block of code that executes when called. Arguments can be imputed and values can be outputted by the function
Describe the parts of a function definition.
Function keyword, function name with parenthesis (ex. name()) (name is optional), arguments in parenthesis, curly braces that hold the code to be executed, and an optional return key word with the value you want to be returned
Function fxnName(parameter1, parameter2) { code here; return outputValue };
Describe the parts of a function call.
fxnName(argument1, argument2);
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition has the definition block and the function keyword, calling it just requires the name and necessary arguments/parameters
What is the difference between a parameter and an argument?
Parameters are only used as variables to store the inputted arguments, arguments are what are inputted and are already defined data types.
Why are function parameters useful?
They are useful by making it easier for a function to be repeatable and to take values from other data in our program
What two effects does a return statement have on the behavior of a function?
It returns a value from the function and also ends the function’s execution.
Why do we log things to the console?
To check or code to see if functions and methods work properly, arrays and variables are filled and assigned.
What is a method?
A method is a function that is a property of an object.
How is a method different from any other function?
Methods are attached to objects, functions aren’t necessarily properties of objects.
How do you remove the last element from an array?
.pop() method
How do you round a number down to the nearest integer?
.floor() method of the Math object
How do you generate a random number?
.random() method of the Math object
How do you delete an element from an array?
.splice(starting index, number of indexes to delete) method
How do you append an element to an array?
Push or unshift method
How do you break a string up into an array?
.split method