Javascript Flashcards
What is the purpose of variables?
To store data to use a later time
How do you declare a variable?
Use the keyword Var
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
Letters, Numbers, Underscores and $
What does it mean to say that variable names are “case sensitive”?
Variables are specific to how they are typed
What is the purpose of a string?
To store and manipulate text
What is the purpose of a number?
To store a value
What is the purpose of a boolean?
To determine if something is false or true
What does the = operator mean in JavaScript?
Assigning a value to a variable
How do you update the value of a variable?
Change the value
What is the difference between null and undefined?
Null is an empty value and Undefined means that variable has been declared but not defined
Why is it a good habit to include “labels” when you log values to the browser console?
Point of reference
Give five examples of JavaScript primitives.
String Numbers Null Undefined Boolean
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
Combination of 2 or more string values
What purpose(s) does the + plus operator serve in JavaScript?
To add values or concatenate strings
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Adds the value of the right operand to the variable and the assigns the result to the variable
What are objects used for?
To group variables or functions
What are object properties?
Variables stored in an obeject
Describe object literal notation.
{properties: 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 Bracket Notation
What are arrays used for?
To be put in a list
Describe array literal notation.
[values, values, values]
How are arrays different from “plain” objects?
Arrays are numeric and will repair themselves if something is deleted
What number represents the first index of an array?
0
What is the length property of an array?
Array.length
How do you calculate the last index of an array?
Array.length - 1
What is a function in JavaScript?
Series of statements that is repeatable
Describe the parts of a function definition.
Function keyword name of function (parameter list) code block return statement function
Describe the parts of a function call.
Name of the function and arguments if it requires it
When comparing them side-by-side, what are the differences between a function call and a function definition?
call has arguments and passes a value and definition has code block with steps
What is the difference between a parameter and an argument?
Parameters are the names listed in the function’s definition Arguments are the real values passed to the function
Why are function parameters useful?
its a tool that is generalized
What two effects does a return statement have on the behavior of a function?
Return statement ends the execution of a function, and returns control to the calling function
Why do we log things to the console?
To debug
What is a method?
Function being stored in a property
How is a method different from any other function?
Methods have to say where they’re coming from
How do you remove the last element from an array?
object.pop()
How do you round a number down to the nearest integer?
object.floor()
How do you generate a random number?
object.random() function getRandomNumberInRange(start,end) { var randomNumber = math.floor(math.random()*(end-start) + 1) + start return randomNumber }
How do you delete an element from an array?
object.splice()
How do you append an element to an array?
object.push() or use object.unshift() to prepend
How do you break a string up into an array?
object.split()
Do string methods change the original string? How would you check if you weren’t sure?
No because strings are immutable. Use console log to debug
Roughly how many string methods are there according to the MDN Web docs?
Alot
Roughly how many array methods are there according to the MDN Web docs?
30
Roughly how many array methods are there according to the MDN Web docs?
Alot
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?
Making decisions
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if (condition) {}
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
&& and ||
What is the purpose of a condition expression in a loop?
To tell the loop when to stop
What is the purpose of a loop?
To allow us to repeat code
What does “iteration” mean in the context of loops?
In the beginning
When does the condition expression of a while loop get evaluated?
The condition is checked before each iteration