JavaScript Flashcards
What is the purpose of variables?
Used to store data
How do you declare a variable?
var variableName;
How do you initialize (assign a value to) a variable?
var variableName = “string”
What characters are allowed in variable names?
letters, numbers, $ , and _.
What does it mean to say that variable names are “case sensitive”?
S != s. Uppercase and lowercase letters will be interpreted differently.
What is the purpose of a string?
Consists of letters and other characters. They are frequently used to add new content to a page and they can contain HTML markup
What is the purpose of a number?
Numeric data types handle numbers.
What is the purpose of a boolean?
Have one of two values: true or false. Booleans are helpful when determining which part of a script should run.
What does the = operator mean in JavaScript?
= assigs a value to a variable
How do you update the value of a variable?
assign a new value to the variable
Why is it a good habit to include “labels” when you log values to the browser console?
To avoid confusion of having multiple console.logs
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining multiple strings together
What purpose(s) does the + plus operator serve in JavaScript?
concatenation and addition
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Adds by a specified value and sets the variable to the value of the expression
What are objects used for?
storing key-value pairs. Used to model real-life objects
What are object properties?
storage areas connected to an object that can store data
Describe object literal notation.
{key: value}
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 bracket notation
What are arrays used for?
Storing data. Particularly useful for lists.
Describe array literal notation.
[ value, value,… ]
How are arrays different from “plain” objects?
They are numerically indexed
What number represents the first index of an array?
0
What is the length property of an array?
.length
How do you calculate the last index of an array?
array.lenght - 1
What is a function in JavaScript?
collection instructions that can be repeated whn called
Describe the parts of a function definition.
function keyword, name, parameter, , the start of the code block, return statement, end of the code block
Describe the parts of a function call.
functionName(arguments)
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call takes arguments in parentheses. a function definition has parameters and code block
What is the difference between a parameter and an argument?
a parameter is a place holder (variable). arguments are the values passes to a parameter
Why are function parameters useful?
allows you to pass information to a function
What two effects does a return statement have on the behavior of a function?
returns a value to function and stops execution of code
Why do we log things to the console?
for debugging
What is a method?
Actions that are performed on objects
How is a method different from any other function?
a method exists as a property on an object. a function can be defined anywhere
How do you remove the last element from an array?
.pop( ) method
How do you round a number to the nearest integer?
.round( ) method
How do you generate a random number?
.random( ) method of the Math object
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. check with console.log.
Roughly how many string methods are there according to the MDN Web docs?
40 - 50
Is the return value of a function or method useful in every situation?
No. Some functions just modify and change things. Others are used to return something
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.
< , > , <=, >=, ==, ===, !=, !==
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
Evaluates a condition to determine if code will be run
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if (condition) {
code block
}
What are the three logical operators?
&& || !
How do you compare two different expressions in the same condition?
With a logical operator
What is the purpose of a loop?
to run a block of code until a certain condition is met
What is the purpose of a condition expression in a loop?
determines whether or not the code is run depending on boolean value
What does “iteration” mean in the context of loops?
each pass through a loop
When does the condition expression of a while loop get evaluated?
at the beginning of each iteration
When does the initialization expression of a for loop get evaluated?
before any code has been run
When does the condition expression of a for loop get evaluated?
at the beginning of each iteration
When does the final expression of a for loop get evaluated?
at the end of each loop
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?
The increment operator (++) increments (adds one to) its operand and returns a value.
How do you iterate through the keys of an object?
for in loop