JavaScript Flashcards
What is the purpose of variables
To store info to use later
How do you declare a variable?
let or var
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
Letters, Numbers, $, _
can’t start with numbers
variables are case sensitive
True
Purpose of strings?
store text
purpose of numbers?
calculations or adjusting CSS
purpose of a boolean?
true or false
what does the = operator mean?
assignment
how do you update the value of a variable?
variable name = new value
null vs undefined?
Nulls are set intentionally by the developer, whereas undefined is set by JS.
Null may indicate that a value will be assigned eventually.
Why is it a good habit to include “labels” when logging values.
Good for debugging.
5 examples of JS Primitives
String, number, Boolean, undefined, null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining strings together into a new string
What purpose does the + plus operator serve in JavaScript?
Adds numbers together or concatenating strings
What data type is returned by comparing two values (, ===, etc.)?
Boolean
What does += do?
Adds a value onto a variable, and then stores that new value into the same variable.
Operant
Value that an operator is operating on
What are objects used for?
Grouping data that are related to eachother
What are object properties?
variables in an object
Describe object literal notation
Key value pairs separated by commas, stored between two curly brackets, and is assigned to a variable. Keys and values are separated with a colon.
How do you remove a property from an object?
Delete operator then use dot notation to choose the property or method
What are two ways to get or update the value of a property?
Dot notation or bracket
What are arrays used for?
Storing information that is related with each other with an order.
Also used when you don’t know how much space you need.
Describe array literal notation.
Values separated by commas within square brackets and then assigned to a variable.
How are arrays different from “plain” objects?
The key is an index number.
What number represents the first index of an array?
0
What is the length property of an array?
Tells you how many items is in the array.
How do you calculate the last index of an array?
You subtract one from the length of the array.
Why do we log things to the console?
debugging and verification
what is a method?
A function that is a property of an object.
How is a method different from any other function?
properties of an object
you can also work with other data part of that 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, pop, shift
How do you break a string up into an array
.split()
Do string methods change the original string?
No
Roughly how many strings are there according to the MDN Web docs?
~40
Roughly how many array methods are there according to the MDN Web docs?
~30
Use MDN
Use MDN
Give 6 examples of comparison operators.
=== >= <= > < !==
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
Decisions
Is else required in order to use an if statement?
No
Describe the syntax of an if statement
conditional statement (condition in parenthesis ) { code block in curly brackets } other conditionals statements if necessary
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
logical operators
What is the purpose of a loop?
To run a set of code one or more times
What is the purpose of a condition expression in a loop?
Tells the loop when to run the code.
Provides a stopping point.
What does “iteration” mean in the context of loops?
It is every time you run through a loop code block.
When does the condition expression of a while loop get evaluated?
It happens before each iteration.
When does the initialization expression of a for loop get evaluated?
It is the first thing that happens.
When does the condition of a for loop get evaluated?
It gets evaluated before each iteration.
When does the final expression of a for loop get evaluated?
It gets evaluated after each iteration.
Besides return, what keyword exits a function block?
break
What does the ++ increment operator do?
adds one
how do you iterate through keys of an object?
for in loop