Javascript Flashcards
What is the purpose of variables
To store data that you assign to it
How do you declare a variable?
Var
How do you initialize (assign a value to) a variable?
Using the assignment operator of =
What characters are allowed in variable name?
Name must begin with a letter, dollar sign, or underscore. CANNOT begin with a number.
What does it mean to say that variable names are “case sensitive”?
That if a variable has the same name as another variable by one is capitalized, they are not considered the same
What is the purpose of a string?
To add text
What is the purpose of a number?
For task that involve counting or calculating sums
What is the purpose of a boolean?
Helpful when determining what steps are required next depending on what conditions are met
What does the = operator mean in Javascript?
The variable’s values is being assigned to the variable’s name
How do you update the value of a variable?
Once you have declared that variable with the var keyword and assigned it a variable name and value, you only need to call the variable name and assign it a new value
What is the difference between null and undefined?
Undefined means that a value was never assigned to the variable and null is essentially a placeholder for a value created by the developer. In null you can place values in, in undefined you cannot.
What is a good habit to include “labels” when you log values to the browser console?
It helps you from getting confused when logging; it is a short string that describes the variable being logged
Give five examples of JavaScript primitives
String, number, boolean, undefined, and null
What data type is returned by an arithmetic operation?
Numbers
What is string concatenation?
When you combine strings together
What purpose(s) does the + plus operator serve in JavaScript?
To perform arithmetic operations or to concatenate strings
What data type is returned by comparing two values (<, >, ===, etc)
Boolean
What does the += “plus-equals” operator do?
Adds a value to an existing variable and assigns the new value back to the same variable
What are objects used for?
They are used to group together a set of variables and methods
What are object properties?
Variables with a name and value
Describe object literal notation
IT is an array of (key:value) pairs that are are placed inside of curly brackets
How do you remove a property from an object?
by using the delete method nameofObject.property
What are the two ways to get or update the value of a property?
Using period notation or square brackets
What are arrays used for?
To store a list of values
Describe array literal notation
You define a new array with empty square brackets
How are arrays different from “plain” objects?
Array are index objects are not
What kind of data types are array?
Reference data types
What is a function in JavaScript?
A set of statements that perform a task or calculates a value
It should take some input and return an output
When comparing them side-by-side, what are the differences between a function call and a function definition?
When you call a function you are only using the name of the function and the parameter you want to put in it
What two effects does a return statement have on the behavior of a function?
Stops the function from running. Returns the function being called
What is the difference if you declare a variable outside vs inside a function?
- If a variable is being defined within a function you can only use it in the function
o If it is declared outside of the function that is fine because you can just give the function a new value in the function
Why do we log things to the console?
To constantly be informed on what our code is doing
what is a method?
Actions that can be performed on objects
How is a method different from any other function?
A method is associated with an object, while a function is not
A method is passed on the object it is called on