JavaScript Flashcards
What is the purpose of variables?
To store pieces of data
How do you declare a variable?
With the var keyword (let,const)
How do you initialize (assign a value to) a variable?
Initialize a variable by assigning it to a value with an equal sign
What characters are allowed in variable names?
Dollar signs, underscores and letters
What does it mean to say that variable names are “case sensitive”
Variable names can be the same word but with different casings. Ex) var pRicE; and var Price; both work
What is the purpose of a string?
For storing and manipulating text
What is the purpose of a number?
Data type to represent and manipulate number values
What is the purpose of a boolean?
a True or false value for all javascript comparison and conditions
What does the=operator mean in JavaScript?
Assignment operator between the variable and data
How do you update the value of a variable?
Assign the variable to a new value; no declaration
What is the difference betweennullandundefined?
- Undefined is not assigned
- Null is an error,
Why is it a good habit to include “labels” when you log values to the browser console?
To confirm what type of data type you are working with, or what value is inside the variable
Give five examples of JavaScript primitives.
Number, boolean, string, null, undefined
What data type is returned by an arithmetic operation?
Depends. Going from left to right of the expression. It’ll work out the math operations then concatenate if a string is there.
What is string concatenation?
Adding two operands together with an addition operator
What data type is returned by comparing two values (,===, etc)?
A boolean value
What does the+=”plus-equals” operator do?
Adds the value on the right of the variable to the left of the operator. Then assigns the result to the variable
What are objects used for?
Allow a collection of data for a specific theme. Data organization
What are object properties?
Variable within an object literal
Describe object literal notation
Key value pairs within curly braces being assigned to a variable name
How do you remove a property from an object?
Using the “delete” operator
What are two ways to get or update the value of a property?
Using dot notation or you can use bracket notation
What are arrays used for?
To list out multiple values of similar data
Describe array literal notation
Square brackets with data divided by commas being assigned to a variable declaration
How are arrays different from “plain” objects
Key numbered index, 0 based
What number represents the first index of an array
0
What is the length property of an array?
Numbers of entries in an array
How do you calculate the last index of an array?
Array[Array.length - 1]
What is a function in JavaScript
Set of reusable code saved under a special type of object to be invoked(called);
Describe parts of a function definition
Curly braces around a code block being assigned to a function definition with parentheses
1. function 2. name(optional) 3. parameters(optional) 4. codeblock 5. return
Describe the parts of a function call
Invoke the name of the function with arguments within the parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition.
Seeing a code block means its a function definition. Then also telling what is an argument and a parameter.
What is the difference between aparameterand anargument?
A parameter is before calling the function
Why are functionparametersuseful?
Pass additional information into the function, couldn’t have dynamic data without it
What two effects does areturnstatement have on the behavior of a function?
Produce a value where the function is called, instead of having undefined.
Can code execute after the return keyword?
No. It finishes after return is ran.
Why do we log things to the console?
To keep track of any updates to variables
What is a method
A function property within an object
How is a method different from any other function?
Method is a function of an object.
How do you remove the last element from an array?
.pop()
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?
.splice, .pop, or shift() all alter the array
How do you append an element to an array?
.push or .unshift()
How do you break a string up into an array?
.split(“ “). Space would divide words
Do string methods change the original string? How would you check if you weren’t sure?
No, because primary data types are immutable. Console.log
Roughly how many string methods are there according to the MDN Web docs?
30
Is the return value of a function or method useful in every situation?
No, because methods like splice();
Roughly how many array methods are there according to the MDN Web docs?
36
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN