JavaScript Flashcards
What is the purpose of variables?
a stored data to use it later on
How do you declare a variable?
var const let
How do you initialize (assign a value to) a variable?
use the assignment operator (=)
What characters are allowed in variable names?
letters, $, _ (underscore); cannot start with number
What does it mean to say that variable names are “case sensitive”?
case should match
What is the purpose of a string?
used with any kind of text; add new content into a page
What is the purpose of a number?
used in calculations and size
What is the purpose of a boolean?
to make a binary decision (true/false)
What does the = operator mean in JavaScript?
value being assign to
How do you update the value of a variable?
name = new value (no need to put var const let, only at first)
What is the difference between null and undefined?
null is intentionally exists (purpose of emptiness for a moment)
undefined exists unintentionally
Why is it a good habit to include “labels” when you log values to the browser console?
helps to track what the value is for
Give five examples of JavaScript primitives.
number, string, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
two or more strings used to create a single value
What purpose(s) does the + plus operator serve in JavaScript?
addition in numeric value or string value
What data type is returned by comparing two values (, ===, etc)?
boolean (true/false)
What does the += “plus-equals” operator do?
allow you to add on anything to current value of variable
What are objects used for?
stores property for variable
What are object properties?
makes what the variable different from other variables (unique)
Describe object literal notation.
opning curly brace for object literal, property, column, value, closing brace
How do you remove a property from an object?
delete operator (delete ___.____);
What are the two ways to get or update the value of a property?
using dot notation or bracket notation
What are arrays used for?
when you need to make a list with not knowing how many needs to be in
Describe array literal notation.
[‘__’, ‘__’]
How are arrays different from “plain” objects?
array has an ordered list (index #)
What number represents the first index of an array?
0
What is the length property of an array?
how many items it holds in the array (not index #)
How do you calculate the last index of an array?
subtract 1 from the length
What is a function in JavaScript?
repeatable and reusable block of code
Describe the parts of a function definition.
keyword, parameter, code block { } , return
Describe the parts of a function call.
name of function
When comparing them side-by-side, what are the differences between a function call and a function definition?
call -> name of function function definition -> keyword, code block, parameter
What is the difference between a parameter and an argument?
parameter -> placeholder for argument
argument -> actual value f0r function to run
Why are function parameters useful?
argument placeholder
What two effects does a return statement have on the behavior of a function?
executes and exits the code block and gives back a value
Why do we log things to the console?
debugging tools
What is a method?
function stored in property of object
How is a method different from any other function?
basically same
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() -> round-down
Math.trunc() -> removes decimal
How do you generate a random number?
Math.random()
How do you delete an element from an array?
splice method (index#, #items)
How do you append an element to an array?
push method
append => add at the end
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
Is the return value of a function or method useful in every situation?
no
Give 6 examples of comparison operators.
=, >, =, logical operator (&&)
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
to make your code to make decision (true/false)
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (condition) code block {}
What are the three logical operators?
&& ll !
How do you compare two different expressions in the same condition?
&& or ll
What is the purpose of a loop?
a repeated block of code happening under certain condition
What is the purpose of a condition expression in a loop?
stop point of the loop
What does “iteration” mean in the context of loops?
one repetition of code block
When does the condition expression of a while loop get evaluated?
before the code bock runs
When does the initialization expression of a for loop get evaluated?
in the beginning (first step)
“before anything”
When does the condition expression of a for loop get evaluated?
after initialization and “before the code block (iteration)
When does the final expression of a for loop get evaluated?
after each iteration, “before the condition”
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
add value of variable
goes up by 1
How do you iterate through the keys of an object?
for in loop
What are the four components of “the Cascade”.
source order/ inheritance/ specificity/ important rule
What does the term “source order” mean with respect to CSS?
order of giving a style matters
last style strongest
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.
element < class < id
Why is using !important considered bad practice?
too strong!!!
Why do we log things to the console?
debugging tool
What is a “model”?
example of a HTML structure
Which “document” is being referred to in the phrase Document Object Model?
HTML document
What is the word “object” referring to in the phrase Document Object Model?
javascript
What is a DOM Tree?
tree of element with all of its HTML children elements
Give two examples of document methods that retrieve a single element from the DOM.
querySelector(‘.name’), getElementById(‘name’)
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll(‘.name’);
Why might you want to assign the return value of a DOM query to a variable?
if you want to access it to multiple times
What console method allows you to inspect the properties of a DOM element object?
console.dir() method - directory method
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
so HTML can run before javascript does
What does document.querySelector() take as its argument and what does it return?
css selector, first element that matches first