JavaScript Flashcards
[JS Primitives and Variables]
What is the purpose of variables?
store temporary bits of information such as strings or numbers for future use
[JS Primitives and Variables]
How do youdeclarea variable?
keywords let, const, var and variable name
[JS Primitives and Variables]
How do you initialize (assign a value to) a variable?
using the equals operator ( = )
[JS Primitives and Variables]
What characters are allowed in variable names?
alphabet letters, numbers, dollar sign ($) and underscore (_)
numbers cannot be used as the first character
[JS Primitives and Variables]
What does it mean to say that variable names are “case sensitive”?
variable names have to be exactly the same, even capitalized letters
[JS Primitives and Variables]
What is the purpose of a string?
storing text which JS cannot read
[JS Primitives and Variables]
What is the purpose of a number?
for tasks involving counting or operations
[JS Primitives and Variables]
What is the purpose of a boolean?
for making decisions / choice (yes or no)
[JS Primitives and Variables]
What does the=operator mean in JavaScript?
assignment operator
[JS Primitives and Variables]
How do you update the value of a variable?
variableName = newValue;
[JS Primitives and Variables]
What is the difference betweennullandundefined?
null is a value that intentionally is nonexistent or invalid
undefined are variables that were not defined
[JS Primitives and Variables]
Why is it a good habit to include “labels” when you log values to the browser console?
to know what is being logged and when the log was called
[JS Primitives and Variables]
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
[JS Operators and Expressions]
What data type is returned by an arithmetic operation?
number
[JS Operators and Expressions]
What is string concatenation?
Adding two strings together
[JS Operators and Expressions] What purpose(s) does the + plus operator serve in JavaScript?
addition & concatenation
[JS Operators and Expressions]
What data type is returned by comparing two values (< , >, ===, etc)?
true or false (boolean)
[JS Operators and Expressions]
What does the += “plus-equals” operator do?
it adds to the original value and assigns the sum as the value
What value is given when trying to multiple, divide or subtract two strings?
NaN (not a number)
[JS Objects]
What are objects used for?
for storing variables and functions (that have similarities)
[CSS Objects]
What are object properties?
bits of information as variables about an object
[CSS Objects]
Describe object literal notation.
var obj = {
property: value,
property: value
}
[CSS Objects]
How do you remove a property from an object?
delete object.property
delete object[‘property’]
[CSS Objects]
What are the two ways to get or update the value of a property?
dot notation or bracket notation
[JS Arrays]
What are arrays used for?
Storing a list or set of variables related to each other.
[JS Arrays]
Describe array literal notation.
var arrayName = [value1, value2, value3, etc.];
[JS Arrays]
How are arrays different from “plain” objects?
objects- have individually named properties and value pairs
arrays- have index number and values
objects don’t have an order
[JS Arrays]
What number represents the first index of an array?
[0]
[JS Arrays]
What is the length property of an array?
shows how many pieces of data are in an array
[JS Arrays]
How do you calculate the last index of an array?
array.length - 1
[JS Functions]
What is a function in JavaScript?
repeatable block of code that does something when called
[JS Functions]
Describe the parts of a function definition.
function keyword optional function name parenthesis optional parameters between parentheses curly braces {} return keyword within curly braces
[JS Functions]
Describe the parts of a function call.
functionName (arguments)
[JS Functions]
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition tells JS what to do (without actually doing it). Contains keyword, parameters and code block.
A function call is simply asking JS to go through the function. Contains function name, arguments and parentheses.
[JS Functions]
What is the difference between a parameter and an argument?
Parameters are part of a definition.
Arguments are part of a function call.
[JS Functions]
Why are function parameters useful?
To show what information is needed for the function to work without having to rewrite a whole function for different arguments.
[JS Functions]
What two effects does a return statement have on the behavior of a function?
- It replaces the function call
2. Stops the function
[JS Methods]
Why do we log things to the console?
To check for desired outputs and that everything is working in the expected.
[JS Methods]
What is a method?
A function that is a property of an object.
[JS Methods]
How is a method different from any other function?
It is called on an object, not through a function name and parenthesis.
[JS Methods]
How do you remove the last element from an array?
array.pop();
[JS Methods]
How do you round a number down to the nearest integer?
Math.floor();
[JS Methods]
How do you generate a random number?
Math.random();
[JS Methods]
How do you delete an element from an array?
array.splice(index, delAmount, item1, …);
[JS Methods]
How do you append an element to an array?
array.push();
[JS Methods]
How do you break a string up into an array?
string.split();
[JS Methods]
Do string methods change the original string?
No
[JS Methods]
Is the return value of a function or method useful in every situation?
No, their functionalities can be used to manipulate data without the use of the value returned.
[JS If statements]
Give 6 examples of comparison operators.
strictly equals === not strictly equal !== greater than > greater than or equals >= less than < less than or equals <=
[JS If statements]
What data type do comparison expressions evaluate to?
boolean: true or false
[JS If statements]
What is the purpose of an if statement?
allows the computer make a decision based on certain stated criteria
[JS If statements]
Is else required in order to use an if statement?
no
[JS If statements]
Describe the syntax of an if statement.
if keyword
parenthesis with condition inside
curly brackets with code to run if true
if (condition) {
code to be executed
}
[JS If statements]
What are three logical operators?
or ||
and &&
not !
[JS If statements]
How do you compare two different expressions in the same condition?
using the and logical operators and && or ||
example: (a == b && c ==d )
[JS Loops]
What is the purpose of a loop?
To repeat a block of code as necessary
[JS Loops]
What is the purpose of a condition expression in a loop?
Tells the loop when to stop running
[JS Loops]
What does iteration mean in the context of loops?
Single run of the loop’s code block
[JS Loops]
When does the condition expression of a while loop get evaluated?
At the beginning of each iteration.
[JS Loops]
When does the initialization expression of a for loop get evaluated?
Once, before the first iteration.
[JS Loops]
When does the condition expression of a for loop get evaluated?
After the initialization and before each iteration
[JS Loops]
When does the final expression of a for loop get evaluated?
After each iteration.
[JS Loops]
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
[JS Loops]
What does the ++ increment operator do?
Increments and substitutes a variable
[JS Loops]
How do you iterate through the keys of an object?
for…in loop
[DOM Querying]
What is a ‘model’?
It’s a representation of elements
[DOM Querying]
Which ‘document’ is being referred to in the phrase Document Object Model?
the whole HTML page
[DOM Querying]
What is the word ‘object’ referring to in the phrase Document Object Model?
refers to the elements on the HTML page that are represented as objects
[DOM Querying]
What is a DOM Tree?
representative chunk of a page as objects
[DOM Querying]
Give two examples of document methods that retrieve a single element from the DOM.
getElementById();
querySelector();
[DOM Querying]
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementsByClassName();
getElementsByTagName();
querySelectorAll();
[DOM Querying]
Why might you want to assign the return value of a DOM query to a variable?
in order to reuse it instead of looking for it everytime you want to manipulate it
[DOM Querying]
What console method allows you to inspect the properties of a DOM element object?
console.dir();
[DOM Querying]
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
So that the HTML elements are loaded first
[DOM Querying]
What does document.querySelector() take as its argument and what does it return?
argument: string (css selector)
returns the HTML element
[DOM Querying]
What does document.querySelectorAll() take as its argument and what does it return?
argument: string (css selector)
returns a node list with all the HTML elements inside
[DOM Events]
What is the purpose of events and event handling?
fire actions for when users interact with a web page
[DOM Events]
Are all possible parameters required to use a JavaScript method or function?
No, some parameters are optional