Javascript Flashcards
What is the purpose of a variable?
to provide a place to store data to access
in the future
How do you declare a variable?
var variable = value
How do you initialize (assign a value to) a variable?
by using =, with variable on left side and value on right
What characters are allowed in variable names?
letters, dollar sign, underscore, numbers(but cannot start with number)
What does it mean to say that variable names are “case sensitive”?
that uppercase and lowercase are entirely separate entities
What is the purpose of a string?
to store non-numerical values + data
What is the purpose of a number?
to store mathematical operations + numerics
What is the purpose of a boolean?
to store the true/false values and make decisions
What does the = operator mean in JavaScript?
to assign
How do you update the value of a variable?
by changing value after the = sign
What is the difference between null and undefined?
null = purposefully put by human programmer undefined = organic javascript
Why is it a good habit to include “labels” when you log values to the browser console?
to make it easier to debug
ALWAYS label
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?
combining two string using concatenation operator (+)
What purpose(s) does the + (plus) operator serve in JavaScript?
- to concatenate
2. to add
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
takes current value of variable and adds new value to variable and returns value of it
What are objects used for?
useful for storing multiple pieces of data that are related to each other
What are object properties?
names of the related pieces of objects
Describe object literal notation.
a set of curly braces, with keys and values within them
How do you remove a property from an object?
the delete operator
What are the two ways to get or update the value of a property?
dot notation and square bracket notation
ALWAYS use dot notation
What are arrays used for?
making lists of related data of the same type
Describe array literal notation
brackets [ } with commas separating values
How are arrays different from “plain” objects?
Arrays have numbered indexes,
objects have alpha numerical indexes
What number represents the first index of an array?
0
What is the length property of an array?
how long the array is /
how many pieces of data are in it
How do you calculate the last index of an array?
the length property of an array - 1
What is a function in JavaScript?
an expression that gives repeatability to a code block
Describe the parts of a function definition.
function keyword, optional name, parameters, function code block, optional return statement
Describe the parts of a function call.
function name, parenthesis, data in parenthesis
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call = no keyword, and no code block
What is the difference between a parameter and an argument?
parameters exist when defining a function,
arguments happen when calling a function
Why are function parameters useful?
they provide re-usability
What two effects does a return statement have on the behavior of a function?
- It stops the function
2. spits out the return value of the function
Why do we log things to the console?
to spit out the current value of things
What is a method?
a function stored as a property on an object
How is a method different from any other function?
methods always need dot (.) before they’re called,
functions can be called by themselves
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() method
How do you generate a random number?
.math.random() method
How do you delete an element from an array?
.splice() method
How do you append an element to an array?
.push() method
How do you break a string up into an array?
.split() method
Do string methods change the original string? How would you check if you weren’t sure?
No, and you can check with console log/MDN
Roughly how many string methods are there according to the MDN Web docs?
Around fifty, A lot
Is the return value of a function or method useful in every situation?
Not always
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.
strictly equal, less than or equal to, more than, more than or equal to, not equal
What data type do comparison expressions evaluate to?
boolean true/false
What is the purpose of an if statement?
let functions make decisions based on conditions
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
keyword if, condition in parenthesis, conditional code block
What are the three logical operators?
&& - and
|| - or
! - not
How do you compare two different expressions in the same condition?
using && - and or || - or
What is the purpose of a loop?
to keep repeating a chunk of code until a certain condition is met
What is the purpose of a condition expression in a loop?
to help stop the loop
What does “iteration” mean in the context of loops?
each time the code block runs
When does the condition expression of a while loop get evaluated?
before each iteration
When does the initialization expression of a for loop get evaluated?
in the beginning, once
When does the condition expression of a for loop get evaluated?
after the final expression, and right before the code block
When does the final expression of a for loop get evaluated?
right after each iteration
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break statement
What does the ++ increment operator do?
adds one to whatever the value is
How do you iterate through the keys of an object?
for ..in loops
Why do we log things to the console?
To inspect their value and make sure it’s up to par
What is a “model”?
A representation of something
Which “document” is being referred to in the phrase Document Object Model?
The HTML document
What is the word “object” referring to in the phrase Document Object Model?
An object model of the HTML document
What is a DOM tree?
A JavaScript object for an HTML element that holds all of its children and children’s contents, values, text content and attributes
Give two examples of document methods that retrieve a single element from the DOM.
GetElementByID, querySelector
Give one example of a document method 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?
To go back and adjust it later