JavaScript Flashcards
Up until learning about OOP and ES6 and the event loop
What is the purpose of variables?
To store data for use later on
How do you declare a variable?
Var keyword and variable name
How do you initialize (assign a value to) a variable?
Variable Name = Variable Value
What characters are allowed in variable names?
letters, underscore, dollar sign, numbers (can’t start with this)
What does it mean to say that variable names are “case sensitive”?
There must be consistency in the way names are typed with capitalization
What is the purpose of a string?
Safe enclosure for text data. Add new content to a page.
What is the purpose of a number?
For math and other tasks like size of screen, moving the position of an element on a page, or setting the amount of time an element should take to fade in.
What is the purpose of a boolean?
Generates true or false to determine which part of script should run
What does the = operator mean in JavaScript?
Storing Values
How do you update the value of a variable?
Variable name = new value
What is the difference between null and undefined?
Null: can only exist if it is purposely assigned; acts as a purposeful empty much like a placeholder
Undefined: this is something uses to say nothing or ‘I don’t know’
Why is it a good habit to include “labels” when you log values to the browser console?
Easier for debugging
Give five examples of JavaScript primitives.
String, Number, Boolean, Null, Undefined
What data type is returned by an arithmetic operation?
Numeric
What is string concatenation?
Using the concatenation operator (+)
What purpose(s) does the + plus operator serve in JavaScript?
Concatenation and Math
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
The current value of variable + new value is a result of the new value of the original variable.
What are objects used for?
Grouped data of a set of variables and functions in relation to each other
What are object properties?
Variables that are part of an object
Describe object literal notation.
Curly braces with key value pairs
How do you remove a property from an object?
Delete operator
What are the two ways to get or update the value of a property?
Dot notation and square bracket notation
What are arrays used for?
Making lists of related data as the same type
Describe array literal notation.
[ ] with comma separated values
How are arrays different from “plain” objects?
Array: numbered indexes, uses [ ], has order and is less customizable
Objects: has properties, alphanumerical, uses { }, has no order and has more ability to be changed
What number represents the first index of an array?
0
What is the length property of an array?
Total number of values in an array
How do you calculate the last index of an array?
Length property of an array - 1
What is a function in JavaScript?
Reusable block of code instead of always repeating a set of instructions.
Describe the parts of a function definition.
Function Keyword Name (Optional) Parameter (Optional) Code Block Return Value (Optional)
Describe the parts of a function call.
Function name and argument
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function calls do not have the code block and function keyword
What is the difference between a parameter and an argument?
Parameter - used for function definition
Arguments - used for function call
Why are function parameters useful?
Allows the function to be more reusable by giving you more clarity on what arguments need to be called.
What two effects does a return statement have on the behavior of a function?
Stops function and gives return value.
Why do we log things to the console?
To check work and to debug
What is a method?
A function which is a property of an object
How is a method different from any other function?
Methods have a . with an object. We need to know where the function is coming from
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 - generates 0 to 1 usually used for percentage to multiply against
How do you delete an element from an array?
.splice ( ) leaving out the parameters of item1, item2, item3 etc.
How do you append an element to an array?
.push ( )
How do you break a string up into an array?
.split ( )
Do string methods change the original string? How would you check if you weren’t sure?
No. You can check through console.log or MDN
Roughly how many string methods are there according to the MDN Web docs?
A lot
Is the return value of a function or method useful in every situation?
No not all the time sometimes it is just part of the sequence of steps.
Roughly how many array methods are there according to the MDN Web docs
A lot
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
==, !=, ===, !==, , >=, <=
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
Helps code make a decision