JavaScript Flashcards
what is the purpose of a variable?
variables store a value of something
how do you declare a variable?
use the keyword var then the name of the variable
How do you initialize (assign a value to) a variable?
You’d use the assignment operator
What characters are allowed in variable names?
underscore dollar sign and letters
What does it mean to say that variable names are “case sensitive”?
If its not case sensitive then they are different values
What is the purpose of a string?
A series of characters in a row. Data that is not code.
What is the purpose of a number?
Calculations
What is the purpose of a boolean?
To represent logic values
what does the = operator mean in JS
the assignment operator
How do you update the value of a variable
set the value to the right of the assignment operator
What is the difference between null and undefined?
Null is a placeholder and undefined is javascript way of saying empty
They both mean empty, lack of value datatypes. Undefined is under the control of javascript. Null has to be assigned by an assignment operator. Somewhere down the line of history a human being came down and assigned null.
Why is it a good habit to include “labels” when you log values to the browser console?
It’ll give us a point of reference.
Give five examples of JavaScript primitives.
Strings, boolean, undefined, numbers, and null.
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
adds numbers and concatenates strings together
What purpose(s) does the + plus operator serve in JavaScript?
its the addition operator
What data type is returned by comparing two values (, ===, etc)?
a boolean
What does the+=”plus-equals” operator do?
The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
to create a model of something you would recognize in the real world. All stored together in one area
What are object properties
They tell us about the object, variables that live inside an object.
Describe object literal
the object name curly braces and key value pairs
How do you remove a property from an object?
delete operator
What are two ways to get or update the value of a property?
dot and bracket notation
What are arrays used for?
It stores a list of values/groups of similar data.
describe array literal notation
variable then bracket index values end with comma brackets
how are arrays different from “plain” objects
Arrays are listed in an order, individually named, set length will repair themselves if an index is deleteds
What number represents the first index of an array
0
What is the length property of an array?
array.length gives the total amount of index in an array
How do you calculate the last index of an array
array.length - 1
What is a function?
A repeatable chunk of code with a specific purpose
Describe parts of a function definition
function keyword and name then parameters then curly braces then code inside
Describe parts of the function call
function name parentheses argument semi colon
When comparing them side by side, what are the differences between a function call and function definition?
Definition has a code block and function keyword
What is the difference between a parameter and an argument?
Parameters are placeholders for arguments that doesn’t have a value that is known. Used when defining thefunction while arugments are used when calling
Why are function parameters useful?
They are placeholders for the arguments. If there were no parameters the behavior would always be the same. It gives us the ability to allow our behavior to act based on a certain set of values
What two effects does a return statement have on the behavior of a function?
It causes the function to produce a value we can use in our program and prevents anymore code from running.
Why do we log things to the console?
to test debugging and inspect if our code works
What is a method?
a function which is a property of an object
How is a method different from other functions
they are 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?
Math.floor()
How do you generate a random number?
Math.Random()
How do you delete an element from an array?
pop()
how do you append an element to an array?
push method
how do you break a string into an array?
split method
Do string methods change the original string?
They do not and console.log the original string and go to MDN
roughly how many string methods are there according to the MDN docs?
a lot