JavaScript Flashcards
What is the purpose of variables?
Variables are meant for storing values.
How do you declare a variable?
var variableName;
How do you initialize (assign a value to) a variable?
variableName = value;
What characters are allowed in variable names?
Alphabet characters, underscores, dollar signs, numbers (but not in the first char).
What does it mean to say that variable names are “case sensitive”?
name and Name are separate variables.
What is the purpose of a string?
To store lists of characters, useful for communicating information to humans or computers.
What is the purpose of a number?
To store numerical values for record keeping or calculation.
What is the purpose of a boolean?
Storing true/false values, used in control flow.
What does the = operator mean in JavaScript?
The right value is being assigned to the left variable.
How do you update the value of a variable?
varName = value;
What is the difference between null and undefined?
Null is intentional, undefined is usually not.
Why is it a good habit to include “labels” when you log values to the browser console?
So you know what’s being logged.
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
Number.
What is string concatenation?
Putting two or more string values together to form a greater string
What purpose(s) does the + plus operator serve in JavaScript?
Arithmetic addition and concatenation.
What data type is returned by comparing two values?
Booleans.
What does the += “plus-equals” operator do?
Add what’s on the right to current value of variable then assign result to the variable.
What are objects used for?
Storing variables and functions associated with a particular entity.
What are object properties?
Values stored in an object.
Describe object literal notation.
var objNew = { prop1: value, prop2: value }
How do you remove a property from an object?
delete obj.property;
What are the two ways to get or update the value of a property?
Dot and bracket notation.
What are arrays used for?
Storing ordered lists of values.
Describe array literal notation.
var array = [0, 1, 2, 3];
How are arrays different from “plain” objects?
Entries inside the array are ordered and indexed by number instead of property names, new entries are added by pushing.
What number represents the first index of an array?
0
What is the length property of an array?
Property of the array that contains how many entries it currently holds.
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
A special type of object that can be called, containing reusable code.
Describe the parts of a function definition.
function keyword, optional name, zero or more parameters, code-block, and a return statement.
Describe the parts of a function call.
Function name, parentheses, arguments if any.
When comparing them side-by-side, what are the differences between a function call and a function definition?
Call passes arguments and executes the code, definitions only specify parameters and code.
What is the difference between a parameter and an argument?
Parameters are placeholders, arguments contain actual values.
Why are function parameters useful?
They can act as placeholder variables for the expressions you want to evaluate so you can reuse functions with different variables.
What two effects does a return statement have on the behavior of a function?
It produces a value and ends the function.
Why do we log things to the console?
To check their values.
What is a method?
A function contained in an object.
How is a method different from any other function?
A method usually involves manipulating or retrieving data from within the object and is called as a property of the object.
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(num)
How do you generate a random number?
Math.floor(Math.random * (max - min + 1) + min)
How do you delete an element from an array?
array.pop() or array.shift()
How do you append an element to an array?
array.push()