JavaScript Flashcards
What is the purpose of variables?
Stores data
How do you declare a variable?
Variable keyword + variable names = variable value;
Must give variable a name
How do you initialize (assign a value to) a variable?
Assign the value using an assignment operator
= sign
What characters are allowed in variable names?
$ or underscore
What does it mean to say that variable names are “case sensitive”?
camelCase - first word lowercase, any additional words have first letter capitalized
What is the purpose of a string?
Working with any kind of text to add new content to a page
Can contain HTML markup
What is the purpose of a number?
Involves counting or calculating sums
Numeric values
What is the purpose of a boolean?
Give values of true or false
Helps determine which part of the script should run
What does the = operator mean in JavaScript?
Assignment operator
Assigns names to value
How do you update the value of a variable?
Change the value
What is the difference between null and undefined?
Null: intentional absence of the value. Undefined: It means the value does not exist in the compiler.
Why is it a good habit to include “labels” when you log values to the browser console
Name of what is for
helps self and others to define what it is used for
Give five examples of JavaScript primitives.
undefined, null, boolean, string, and number
What data type is returned by an arithmetic operation?
Numeric
What is string concatenation?
Process of joining two or more strings to create one new string
What purpose(s) does the + plus operator serve in JavaScript?
Addition as well as concatenation
What data type is returned by comparing two values (, ===, etc)?
Comparison operators
What does the += “plus-equals” operator do?
adds the value of the right operand to a variable and assigns the result to the variable
What are arrays used for?
Storing values as a list
Describe array literal notation.
Values assigned to the array inside of a pair of square brackets, each value separated by a comma.
Don’t need to be same data type
How are arrays different from “plain” objects?
Can combine arrays and objects to create a data structure
What number represents the first index of an array?
0
What is the length property of an array?
sets or returns the number of elements in an array
How do you calculate the last index of an array?
Name.length - 1
Why do we log things to the console?
Making sure everything is working and running correctly
What is a method?
Function which is a property 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?
unshift()
push()
How do you break a string up into an array?
Call the split() method
Do string methods change the original string? How would you check if you weren’t sure?
No, immutable - log it to the console
Roughly how many string methods are there according to the MDN Web docs?
50+
Allow work with strings after been created
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
3
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.
< - less than, > - greater than, != - not equal to, || - logical or, === - strictly equal to, && - logical and
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
Evaluates (checks) a condition
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
Keyword, condition, opening curly brace, code to execute if value true, closing curly brace
What are the three logical operators?
&& - logical and, || logical or, ! logical not
How do you compare two different expressions in the same condition?
Using a logical and && - logical or ||
What is the purpose of a loop?
Check a condition that will run the code block
Repeat a block of code
What is the purpose of a condition expression in a loop?
Is evaluated n gets tested every time the loop runs
It determines if and when the loop stops.
What does “iteration” mean in the context of loops?
Means how many times the loop will loop.
When does the condition expression of a while loop get evaluated?
evaluated before each pass through the loop
Before each iteration to decide whether we should stop or not
When does the initialization expression of a for loop get evaluated?
evaluated once before the loop begins
When does the condition expression of a for loop get evaluated?
evaluated before each loop iteration
When does the final expression of a for loop get evaluated?
evaluated at the end of each loop iteration
After the code block runs
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?
Adds one to the operand.
How do you iterate through the keys of an object?
Using the for in loop.
Why do we log things to the console?
Checks to see if the code is running and working properly
What is a “model”?
Representation of something
Which “document” is being referred to in the phrase Document Object Model?
The elements of the page
What is the word “object” referring to in the phrase Document Object Model?
Each node is an object with methods and properties
What is a DOM Tree?
Model of the webpage
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.
document.querySelectorAll()
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll()