JavaScript ES5 Flashcards
What is the purpose of variables?
Store data for future access
How do you declare a variable?
var quantity;
How do you initialize (assign a value to) a variable?
quantity = 3;
What characters are allowed in variable names?
Letters
Numbers (cannot start with)
$
_
What does it mean to say that variable names are “case sensitive”?
Variables are stored with case sensitive names
What is the purpose of a string?
Represent text
What is the purpose of a number?
Mathematical operations
What is the purpose of a boolean?
Used with conditional logic to run specific blocks of code
What does the = operator mean in JavaScript?
Assignment operator assigns values to variables
How do you update the value of a variable?
let quantity = 3;
//reassign quantity = 7;
What is the difference between null and undefined?
null:
a non-existent value that is intentionally assigned by the user, usually a placeholder value
undefined:
a non-existent value that is automatically assigned by JavaScript if no value is given
Give five examples of JavaScript primitives.
Number String Boolean Null Undefined
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
Combination of at least one string value with another string value or primitive value
What purpose(s) does the + plus operator serve in JavaScript?
Addition
Concatenation
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Addition Assignment:
Adds the left value with the right value, and the result of this expression is reassigned to the left
What are objects used for?
Encapsulating characteristic data by key value pairs
What are object properties?
Variables inside of an object
Describe object literal notation.
var obj = {};
How do you remove a property from an object?
delete hotel.booked;
What are the two ways to get or update the value of a property?
Dot Notation:
vehicle.color = black
Bracket Notation:
vehicle[“color”] = “black”
What are arrays used for?
Store a list of numerically, zero based indexed data, where order may matter
Describe array literal notation.
var array = [];
How are arrays different from “plain” objects?
- Numerical Indexes
- Ordered
- Special methods to modify array values (push, pop, shift, unshift, splice, etc)
What number represents the first index of an array?
0
What is the length property of an array?
Returns the number of array entries
How do you calculate the last index of an array?
arr[arr.length – 1]
What is a function in JavaScript?
A set of reusable code
Describe the parts of a function definition.
let endOfSentence = ‘something’
function example (params) { return 'I am returning ' + params; }
Describe the parts of a function call.
example(endOfSentence)
“I am returning something”
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call:
- No code block
- arguments
Function Definition:
- function keyword
- Code block
- return statement
- parameters
What is the difference between a parameter and an argument?
Parameter exist in function definitions and are placeholders (variables)
Argument are passed into a function’s parameters in a function call as values
Why are function parameters useful?
Allow for dynamic data and reusability
What two effects does a return statement have on the behavior of a function?
Returns the output of the function
Immediately exits the function
How is a method different from any other function?
Methods are attached to objects
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(start index, [delete count], [replacement]);
array. spice(3, 1)
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?
String methods DO NOT change the original string
Check by console.log the original string after using the method
Is the return value of a function or method useful in every situation?
No
Give 6 examples of comparison operators.
> (gt) < (lt) <= (lte) >= (gte) === (strictly equal) !== (not strictly equal)
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
Take decisions on code based on if a specified condition is truthy, if falsy the else block can run
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if (condition) { //code block to run if condition is met }