Javascript Flashcards
What is the purpose of variables?
To store data to use again in the future.
How do you initialize (assign a value to) a variable?
var keyword var name = var value;
What characters are allowed in variable names?
Letters, Numbers, Underscore, and dollarsign.
What does the = operator mean in JavaScript?
Assignment.
What does it mean to say that variable names are “case sensitive”?
Uppercase and lowercase variable names are not equal,
What is the purpose of a string?
sequence of characters that represent text
What is the purpose of a number?
represents a numeric data type that allows us to perform mathematical operations on it
What is the purpose of a boolean?
Lets the computers ultimately decide what to do or not do.
What is the difference between null and undefined?
undefined: JavaScript’s method of saying “empty”
null: developer’s way of saying “empty”; assigned intentionally
What data type is returned by an arithmetic operation?
number
What is string concatenation?
adding two strings together
What purpose(s) does the + plus operator serve in JavaScript?
addition and string concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds/concatenates the value on the right with the value on the left and then assigns it to the variable on the left.
What are objects used for?
to group relevant data together
What are object properties?
variables that live within an object
Describe object literal notation.
var keyword var name = { };
How do you remove a property from an object?
Using the delete operator
delete object.property
What are the two ways to get or update the value of a property?
dot notation (object.property = value)
bracket notation (object[‘property’] = value)
What are arrays used for?
Useful when working with lists or groups of similar data
Describe array literal notation.
var varName = [list contents (separated by comma)]
How are arrays different from “plain” objects?
values assigned to index numbers rather than keys
order is preserved in arrays
What number represents the first index of an array?
0
What is the length property of an array?
returns how many things are stored in the list
How do you calculate the last index of an array?
array.length - 1
Give five examples of JavaScript primitives.
Number, Boolean, String, Null, Undefined
Why is it a good habit to include “labels” when you log values to the browser console?
To know which variable you are logging.
How do you update the value of a variable?
var name = new value;
How do you declare a variable?
Var keyword var name;
What is a function in JavaScript?
A block of code that has a specific purpose and can be reused as many times as needed
Describe the parts of a function definition.
function functionName (optional Parameter) { optional Return; }
Describe the parts of a function call.
functionName( );
What is the difference between a parameter and an argument?
Functions are defined with parameters and called with arguments.
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value and also exits the function.
Why are function parameters useful?
Can achieve different results depending on the data passed in
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition has parameters and a code block and function call has arguments.
Why do we log things to the console?
To check if the value received is as expected.
What is a method?
A function that is a property of an object.
How is a method different from any other function?
They are accessed using dot notation.
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?
Array.splice( )
How do you append an element to an array?
Array.push( )
How do you break a string up into an array?
String.split( )
Do string methods change the original string? How would you check if you weren’t sure?
No, string are immutable. Console log.
Roughly how many string methods are there according to the MDN Web docs?
36.
Roughly how many array methods are there according to the MDN Web docs?
35.
Is the return value of a function or method useful in every situation?
No.
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
How do you remove the last element from an array?
Array.pop( )
Give 6 examples of comparison operators.
==, !=, ===, , >=, <=
What data type do comparison expressions evaluate to?
Boolean.
What is the purpose of an if statement?
To make a decision
Is else required in order to use an if statement?
No.
Describe the syntax (structure) of an if statement.
if (condition){
code to be exectuted;
}
What are the three logical operators?
logical And (&&), Logical Or ( || ), Logical Not ( ! )
How do you compare two different expressions in the same condition?
&& or | |
What is the purpose of a loop?
Repeat code until condition is met.
What is the purpose of a condition expression in a loop?
To tell the loop when to stop running.
What does “iteration” mean in the context of loops?
One full pass of the loops code block.
When does the condition expression of a while loop get evaluated?
Before each Iteration.
When does the initialization expression of a for loop get evaluated?
Once, before the loop begins.
When does the condition expression of a for loop get evaluated?
After the final expression and before each iteration.
When does the final expression of a for loop get evaluated?
After each iteration.
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?
Increments by 1.
How do you iterate through the keys of an object?
For in loop.