Javascript Flashcards
What is the purpose of variables?
To store data to be accessed later.
How do you declare a variable?
Var keyword variable Name; (var quantity;)
How do you initialize (assign a value to) a variable?
Var keyword var Name = var value; (var quantity = 3;)
What characters are allowed in variable names?
Letters, number, dollar sign, or underscore
What does it mean to say that variable names are “case sensitive”?
Using the same variable name must have the same lowercase or uppercase letters.
What is the purpose of a string?
To store data made up of text
What is the purpose of a number?
To store numeric data / for tasks that involve counting or calculating
What is the purpose of a boolean?
To store true or false data / binary data.
What does the = operator mean in JavaScript?
Assignment
How do you update the value of a variable?
Variable name = new value;
What is the difference between null and undefined?
Null is intentionally left with no value and undefined is declared to variables that have not been assigned a value yet.
Why is it a good habit to include “labels” when you log values to the browser console?
To add a description of the variable/value 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?
Adding a string value with another value
What purpose(s) does the + plus operator serve in JavaScript?
Adds one value to another
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
It adds the value of the var on the right to the current value of the var on the left which then equals the var on the left.
What are objects used for?
To store multiple pieces of data in one variable / to organize data
What are object properties?
Individual variables stored in an object.
Describe object literal notation.
Var keyword variable name holding the object = { };
How do you remove a property from an object?
Delete operator . property name; OR delete property[‘property name’];
What are the two ways to get or update the value of a property?
Dot notation and bracket notation
What are arrays used for?
To store a list of values. (mainly for similar data)
Describe array literal notation.
Var keyword variableName = [ ];
How are arrays different from “plain” objects?
The key for its’ value is a numeric index.
What number represents the first index of an array?
0
What is the length property of an array?
.length / holds the number of pieces of data in the array.
How do you calculate the last index of an array?
Array.length - 1;
What is a function in JavaScript?
Special type of object that can be called. Set of reusable code.
Describe the parts of a function definition.
Function keyword optionalFuncName ( parameter, ) {
Optional Return;
}
Describe the parts of a function call.
functionName()
When comparing them side-by-side, what are the differences between a function call and a function definition?
Call passes in argument/values .. definition has code block
What is the difference between a parameter and an argument?
Parameter is in definition(placeholder) and argument is in call(value).
Why are function parameters useful?
Gives more uses to the function since data can be passed in through the parameter.
What two effects does a return statement have on the behavior of a function?
Produce a value /
Why do we log things to the console?
To see if the code runs properly / check if any errors
What is a method?
A function stored within a property in an 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()
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?
.push()
How do you append an element to an array?
.push() / .unshift()
Do string methods change the original string? How would you check if you weren’t sure?
No.
Is the return value of a function or method useful in every situation?
Not always.