JavaScript Flashcards
What is the purpose of variables?
to store data to use later on
How do youdeclarea variable?
keyword like var let or const
How do you initialize (assign a value to) a variable?
With the assignment operator =
What characters are allowed in variable names?
underscore, $, letters (upper/lower) numbers
What does it mean to say that variable names are “case sensitive”?
Having an uppercase letter will declare a different variable
What is the purpose of a string?
To represent text, that is not code
What is the purpose of a number?
to perform calculations
What is the purpose of a boolean?
how we make decisions in code
to identify data as either true or false
What does the=operator mean in JavaScript?
that you are assigning a value to a variable
How do you update the value of a variable?
assign another value to it
What is the difference betweennullandundefined?
Null is used intentionally, null can only be assigned. Either it’s empty because you are going to update it later or to signify nothing will be there.
undefined is used by the computer to signify an error
Why is it a good habit to include “labels” when you log values to the browser console?
For debugging, but also to organize your data so you know what you are looking at
Give five examples of JavaScript primitives.
String, boolean, number, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
addition for strings
What purpose(s) does the+plus operator serve in JavaScript?
addition (numbers) or concatenation (strings)
What data type is returned by comparing two values (,===, etc)?
boolean
What does the+=”plus-equals” operator do?
adds the assigned value to the variable
What are objects used for?
Store data that are related
What are object properties?
Variables within a group
Describe object literal notation.
curly brackets properties and values
How do you remove a property from an object?
Delete operator
What are the two ways to get or update the value of a property?
dot notation and/or bracket notation
what are arrays used for?
Store related content in a list
Describe array literal notation.
Square brackets, values separated by comma
How are arrays different from “plain” objects?
The way the data is accessed (arrays have index numbers)
numeric indexes, objects have alphanumeric indexes
Order: Arrays have order, objects do not
Brackets
What number represents the first index of an array?
0
What is thelengthproperty of an array?
array.length
property that contains a true count of each piece of data
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
a repeatable block of code with the potential to receive and return different values. Functions allow you to package up code for use later on.
Describe the parts of a functiondefinition.
thefunctionkeyword anoptionalname zero or moreparameters acode block anoptionalreturnstatement
Describe the parts of a functioncall.
name of the function, parenthesis, arguments (if any)
When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
function definition has a code block, parameters, and a possible return statement
What is the difference between aparameterand anargument?
A parameter is a place holder for the argument within a function. An argument represents the values being passed into the function.
Why are functionparametersuseful?
The are the placeholders for values passed into the function through arguments
What two effects does areturnstatement have on the behavior of a function?
The return statement ends function execution and specifies a value to be returned to the function caller.
What is a method?
Amethodis afunction which is apropertyof anobject
How is a method different from any other function?
no difference
How do you remove the last element from an array?
the pop method .pop()
How do you round a number down to the nearest integer?
Math.floor() rounds a number down
Math.trunc() chops decimal
How do you generate a random number?
Math.random()
How do you delete an element from an array?
.splice(start, deleteCount)
How do you append an element to an array?
.push()
How do you break a string up into an array?
.split()
Do string methods change the original string? How would you check if you weren’t sure?
No. console.log(originalString)
Is the return value of a function or method useful in every situation?
No (insert and example)
Give 6 examples of comparison operators.
=== !== > < >= <=
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of anifstatement?
So the code can perform actions or make decisions
Iselserequired in order to use anifstatement?
No
Describe the syntax (structure) of anifstatement.
if keyword followed by a condition followed { wrap a code block } and execute if that condition is true.
What are the three logical operators?
&& || !
How do you compare two different expressions in the same condition?
logical and or logical or && ||
What is the purpose of a loop?
a repeated block of code happening under some condition
What is the purpose of aconditionexpression in a loop?
testing whether a condition is true or false, condition is the brakes. True it keeps going, false it stops.
What does “iteration” mean in the context of loops?
how many times it will run, one iteration of the code at a time.
Whendoes theconditionexpression of awhileloop get evaluated?
Before the code block runs
Whendoes theinitializationexpression of aforloop get evaluated?
1st
Whendoes theconditionexpression of aforloop get evaluated?
Before each iteration
Whendoes thefinalexpression of aforloop get evaluated?
After each iteration and before the condition
Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?
Break
What does the++increment operator do?
it adds 1 to the variable
How do you iterate through the keys of an object?
for in loop
why do we log things to the console?
As a debugger / to label and to create check marks
Which “document” is being referred to in the phrase Document Object Model?
HTML