JavaScript Flashcards
What is the purpose of variables?
Store data
How do you declare a variable?
with var
How do you initialize (assign a value to) a variable?
with the assignment operator (=)
What characters are allowed in variable names?
Letters, Characters, numbers, nonpunctuation characters
What does it mean to say that variable names are “case sensitive”?
sensitive to uppercase and lowercase letters
What is the purpose of a string?
to display text
What is the purpose of a number?
For any numeric function
What is the purpose of a boolean?
True or False
What does the = operator mean in JavaScript?
it assigns a value
How do you update the value of a variable?
using the dot (.)
What is the difference between null and undefined?
Null is an assigned value, Undeclared has not been assigned.
Why is it a good habit to include “labels” when you log values to the browser console?
To show you what you are logging
Give five examples of JavaScript primitives.
string, number, null, boolean, undefined
What is string concatenation?
Adding two or more strings together
What purpose(s) does the + plus operator serve in JavaScript?
to combine
What data type is returned by comparing two values (, ===, etc)?
true or false
What does the += “plus-equals” operator do?
adds the variable on the right to the left and assigns it back into the variable on the left
What are objects used for?
to store multiple properties, and to know where the data is, and to use that data together
What are object properties?
a single value stored on an object
Describe object literal notation.
var followed by curly braces with properties inside
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?
with the dot or brackets
What are arrays used for?
a data structure that stores a collection of data
Describe array literal notation.
An array literal is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ( [] ).
What number represents the first index of an array?
0
What is the length property of an array?
Calculates the total length of an array
How do you calculate the last index of an array?
-1
Why do we log things to the console?
console.log
What is a method?
a method is a function which is a property of an object
How is a method different from any other function?
it is a object reference to a function
How do you remove the last element from an array?
.pop() method
How do you round a number down to the nearest integer?
.floor() method
How do you generate a random number?
.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 they dont
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?
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.
==, !=, ===, !==, >, =, <=
equal, not equal to, strictly equal, strictly inequal, greater than
What data type do comparison expressions evaluate to?
boolean: true, false
What is the purpose of an if statement?
it allows your code to execute the statement between the brackets or to go on to the else
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (condition) {statement} else
What are the three logical operators?
&&, ||, and ~
How do you compare two different expressions in the same condition?
==
What is the purpose of a loop?
To loop throat a a condition until something is executed
What is the purpose of a condition expression in a loop?
to evaluate if something is true or false
What does “iteration” mean in the context of loops?
the amount of times it repeats
When does the condition expression of a while loop get evaluated?
before the loop
When does the initialization expression of a for loop get evaluated?
at the beginning of the loop
When does the condition expression of a for loop get evaluated?
after the initialization
When does the final expression of a for loop get evaluated?
In the return statement
Why do we log things to the console?
to let us know what we are doing
What is a method?
A method is a function which is a property of an object.
How can you tell the difference between a method definition and a method call?
method definition is going to have everything and a method call is the name of the object.method()
What is a code block? What are some examples of a code block?
A code block uses curly braces to group zero or more statements. var x = 1; let y = 1;
if (true) { var x = 2; let y = 2; }
What does block scope mean?
Not attached to global scope
What is the scope of a variable declared with const or let?
Block Scoped
What is the difference between let and const?
Let is not initialized to any value, Const creates a read-only reference to a value
Why is it possible to .push() a new value into a const variable that points to an Array?
It allows you to change the arrays elements, however you cannot reassign the array to another array
How should you decide on which type of declaration to use?
use let if the variable’s value will change during the code
What is the syntax for writing a template literal?
use the backtick ( ` ) character
What is “string interpolation”?
the process of embedding an expression into part of a string.
What is destructuring, conceptually?
extracting data from arrays or objects