JavaScript Flashcards
What is the purpose of variables?
it can stores bits of information and can be reuse/recall at later time
How do you declare a variable?
var (keyword) nameOfVariable;
How do you initialize (assign a value to) a variable?
nameOfVariable = value;
What characters are allowed in variable names?
letters, numbers, dollar sign($) and underscore(_)
What does it mean to say that variable names are “case sensitive”?
same variable name with uppercase letter will result in another variable
What is the purpose of a string?
to store (text/character) letter, word or sentence
What is the purpose of a number?
to handle calculation or any tools that utilizes number
What is the purpose of a boolean?
to define whether something is true or false (for making decision)
What does the = operator mean in JavaScript?
Assigning / defining
How do you update the value of a variable?
by setting the variable to a new value
What is the difference between null and undefined?
Null = nonexistent or invalid value
Undefined = variable without value(argument)
Null = purposeful emptiness
Undefined = accidental emptiness
Why is it a good habit to include “labels” when you log values to the browser console?
because console.log only return value and it can be hard to keep track which variable it belongs to
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined, symbol, BigInt
What data type is returned by an arithmetic operation?
number
What is string concatenation?
adding second string(argument) behind the first string(argument)
What purpose(s) does the + plus operator serve in JavaScript?
mathematic + or concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
x += y -> x = x + y
Number + boolean = number
Number + string = string
Number + number = number
string + string = string
string + boolean = string
boolean + boolean = number
What are objects used for?
group together variables and function that are related
What are object properties?
variable & value [key], individual pieces of name and data
Describe object literal notation.
var varName = { (property) var: value, var2: value, (method) key: function }
How do you remove a property from an object?
delete object.key
What are the two ways to get or update the value of a property?
object.key or object[‘key’]
What are arrays used for?
to store list of data/information
Describe array literal notation.
var varName = [,];
How are arrays different from “plain” objects?
arrays have key as index for each value,
value in array almost always contain the same type of data,
array comes with length property
What number represents the first index of an array?
0
What is the length property of an array?
amount of items within an array
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
a set of action that is given a name and can be recalled/repeated use
Describe the parts of a function definition.
function keyword functionName (parameter/s) {
code to do stuff
return (optional)
}
Describe the parts of a function call.
functionName(argument/s);
When comparing them side-by-side, what are the differences between a function call and a function definition?
definition define what the function do/return which include many parts. Function call actually run the function and can expect result, only contain name of the function plus parenthesis -> functionName();
What is the difference between a parameter and an argument?
parameter (placeholder) is used when defining function. argument (value) is used when calling the function.
Why are function parameters useful?
so that function can be dynamic and have the ability to do more than 1 thing
What two effects does a return statement have on the behavior of a function?
it can assign result of the function (a value) to a variable that can be used at later time without calling the function again. Another effect is return also exit the function code block
Why do we log things to the console?
debugging, verification
What is a method?
functions built into variables
How is a method different from any other function?
has to be called from a variable
How do you remove the last element from an array?
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?
array.splice(starting index, how many item)
How do you append an element to an array?
array.push()
How do you break a string up into an array?
string.split(separator)
Do string methods change the original string? How would you check if you weren’t sure?
no, console.log it