Javascript Flashcards
What is the purpose of variables?
To store data.
How do you declare a variable?
keyword(var, let, const) with a space followed by the variable number.
How do you initialize (assign a value to) a variable?
Using the assignment operator ‘=’
What characters are allowed in variable names?
start with $ _ or letters, and can have numbers and letters in it.
What does it mean to say that variable names are “case sensitive”?
javascript reads capitals as a differnet letters.
What is the purpose of a string?
To store text data.
What is the purpose of a number?
To store numbers for use in math.
What is the purpose of a boolean?
As a ‘on, off’ switch.
What does the = operator mean in JavaScript?
It assigns the value to a variable.
How do you update the value of a variable?
using a the variable name and assignment operator.
What is the difference between null and undefined?
undefined means the variable has not been assigned a variable. Null is purposefully left unassigned.
Why is it a good habit to include “labels” when you log values to the browser console?
To keep things organized and to know what and why your logging something.
Give five examples of JavaScript primitives.
boolean, number, string, null, undefined.
What data type is returned by an arithmetic operation?
A number
What is string concatenation?
Combining strings togethers.
What purpose(s) does the + plus operator serve in JavaScript?
Add two values to another.
What data type is returned by comparing two values (<, >, ===, etc)?
A boolean value.
What does the += “plus-equals” operator do?
It adds or concatenates two numbers or strings and then assigns to the variable.
What are objects used for?
Used to group together sets of variables and function(methods).
What are object properties?
They are variables describing the variable they are in.
Describe object literal notation.
variable assign with {} and key value property pairs.
How do you remove a property from an object?
use the delete keyword and the property of the object.
What are the two ways to get or update the value of a property?
using dot or bracket notation and assignment operator.
What are arrays used for?
Relevant data or lists of data.
Describe array literal notation.
var array = []
How are arrays different from “plain” objects?
arrays properties are the index
What number represents the first index of an array?
The index starts at 0.
What is the length property of an array?
the .length property shows the number of items.
How do you calculate the last index of an array?
item.length -1 will give the last index since index starts at 0.
What is a function in JavaScript?
Is a special object that can be called to run a block of code.
Describe the parts of a function definition.
function keyword, optional name and optional paramaters and the code block.
Describe the parts of a function call.
function name and optional arguments in ().
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call uses parameters instead of arguments, and does not have the function definition and no code block.
What is the difference between a parameter and an argument?
parameter is an empty variable or placeholder and arguments are values passed through.
Why are function parameters useful?
They allow use to create lines of code to run with the parameters, arguments when you call the function.
What two effects does a return statement have on the behavior of a function?
It produces a usable value and exits the function.
Why do we log things to the console?
We log to the console to see if our output is what we expected.
What is a method?
A method is a function of an object.
How is a method different from any other function?
The method must be called in relation to a object, (arrays and strings are objects?)
How do you remove the last element from an array?
this.pop() removes the last items from an array AND returns it, so it may be assigned to a variable.
How do you round a number down to the nearest integer?
your use the floor() method of the Math object. Math.floor() and pass the number as an argument.
How do you delete an element from an array?
You can use the array.splice() method, with arguments in order.
(start index, number to delete, items to replace, items to replace..), also
array.shift, and array.pop