JavaScript Flashcards
What is the purpose of variables?
To store data into
How do you declare a variable?
var variable name;
How do you initial (assign a value to) a variable?
=
What characters are allowed in variable names?
Letters, numbers, &, _
What does it mean to say that variable names are “case sensitive?”
Variables of the same name have to be typed with the same capitalization
What is the purpose of a string?
Store or manipulate text
What is the purpose of a number?
Store or manipulate numbers
What is the purpose of a boolean?
Data type showing binary states, true/false
What does the = operator mean in JavaScript?
Assigning a value to a variable
How do you update the value of a variable?
Reassign variable to a new value
What is the difference between null and undefined?
Null: non-existent or invalid object, null cannot be created unorganically, purposeful emptiness
Undefined: assigned to a variable with nothing
Why is it a good habit to include “labels” when you log values to the browser?
More clear which variables are being logged and in what order
Give five examples of JavaScript primitives
String, number, bigint, boolean, undefined, symbol, null
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
The joining of two or more strings to create on string
What purpose(s) does the + plus operator serve in JavaScript?
Adding one value to another
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Add the value of the right operand to a variable and assigns the result to a variable
What are objects used for?
Groups a set of variables and functions
What are object properties?
Variables within a certain boundary in a storage location
Describe object literal notation
{ property: value, }
How do you remove a property from an object?
Delete
What are the two ways to get or update the value of a property?
Dot notation, bracket notation
What are arrays used for?
Stores a list of values
Describe array literal notation
[ variable1, variable 2, variable3]
How are arrays different from “plain” objects?
Instead of properties, arrays have index number for values
What number represents the first index of an array?
0
What is the length property of an array?
Total number of values
How do you calculate the last index of an array?
Create new variable (last index), assign to the result of length of array (number of students) minus 1. Create new variable (last student), assign to original array at the index of the new variable (last index). var lastIndex = numberOfStudents - 1; var lastStudent = students[lastIndex];
What is a function in JavaScript?
Reusable block of code
Describe the parts of a functiondefinition.
Name of a function, parameters code block
Describe the parts of a functioncall.
Name of the function, parentheses, argument
When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
Function has keyword, code block and parameter
Call has a name and arguments
What is the difference between aparameterand anargument?
Parameter- placeholder
Argument- variable
Why are functionparametersuseful?
Act as a placeholder
What two effects does areturnstatement have on the behavior of a function?
- Causes the function to produce a value we can use in our program.
- Prevents any more code in the function’s code block from being run.
Why do we log things to the console?
Debugging tool
What is a method?
Functions being called of an object
How is a method different from any other function?
Method is associated with 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
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, console.log
Is the return value of a function or method useful in every situation?
No
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.
greater than, less than, ==, ===, !=, !==, <=, >=
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of anifstatement?
Having your code make a decision
Iselserequired in order to use anifstatement?
No
Describe the syntax (structure) of anifstatement.
If (condition) {
execute
}
What are the three logical operators?
&&, | |, !
How do you compare two different expressions in the same condition?
Logical operators
What is the purpose of a loop?
To repeat a portion of code a set amount of times
What is the purpose of aconditionexpression in a loop?
An expression that is tested every time a code loops
What does “iteration” mean in the context of loops?
One repetition of a code block
Whendoes theconditionexpression of awhileloop get evaluated?
Before the code block runs
Whendoes theinitializationexpression of aforloop get evaluated?
Before anything
Whendoes theconditionexpression of aforloop get evaluated
Before each iteration
Whendoes thefinalexpression of aforloop get evaluated?
After each iteration
Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?
Break
What does the++increment operator do?
Increment by 1
How do you iterate through the keys of an object
Use a for-in loop
What are the four components of “the Cascade”.
Source order, inheritance, specificity & !important
What does the term “source order” mean with respect to CSS?
The styling provided for an element last in your stylesheet is the styling that will ultimately take effect
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule
Inheritance
List the three selector types in order of increasing specificity.
Type, class, id
Why is using!importantconsidered bad practice?
It makes debugging more difficult by breaking the natural cascading in stylesheets
Why do we log things to the console?
Debugging tool
What is a “model”?
A representation of something
Which “document” is being referred to in the phrase Document Object Model?
The whole html file
What is the word “object” referring to in the phrase Document Object Model?
The datatype object
What is a DOM Tree?
Element plus all of its children
Give two examples ofdocumentmethods that retrieve a single element from the DOM.
queryselector, getelementbyname
Give one example of adocumentmethod that retrieves multiple elements from the DOM at once.
queryselectorall
Why might you want to assign the return value of a DOM query to a variable?
Ease of logging
Whatconsolemethod allows you to inspect the properties of a DOM element object?
console.dir
Why would atag need to be placed at the bottom of the HTML content instead of at the top?
Because the html isn’t rendered yet
What doesdocument.querySelector()take as its argument and what does it return?
String, first element in the document with its name
What doesdocument.querySelectorAll()take as its argument and what does it return?
Object, node list
What is the purpose of events and event handling?
To show the action resulting from a user, the code executed once the event takes place
Are all possible parameters required to use a JavaScript method or function?
No
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener
What is a callback function
Function passed into another function as an argument
What object is passed into an event listener callback when the event fires?
Event
What is theevent.target? If you weren’t sure, how would you check? Where could you get more information about it?
Where the event occurred in the DOM, console.log it, MDN