Javascript Flashcards
What is the purpose of variables?
To store data
How do you declare a variable?
Using the variable keyword and variable name
How do you initialize (assign a value to) a variable?
Write the variable name, and use the assignment operator to assign it to a value
What characters are allowed in variable names?
The name can contain letters, numbers, dollar sign ($), or an underscore (_).
What does it mean to say that variable names are “case sensitive”?
the capitalization must be consistent
What is the purpose of a string?
The String object is used to represent and manipulate a sequence of characters.
What is the purpose of a number?
represent and manipulate numbers
What is the purpose of a boolean?
to hold data types of true or false
What does the = operator mean in JavaScript?
assign a value into a variable
How do you update the value of a variable?
name of variable, assignment operator and the new value
What is the difference between null and undefined?
undefined has not been assigned a value yet. null intentionally has no value.
Why is it a good habit to include “labels” when you log values to the browser console?
helpful to debug
Give five examples of JavaScript primitives.
string, number, boolean, undefined and null
What data type is returned by an arithmetic operation?
number value
What is string concatenation?
to add two strings so they become a single value
What purpose(s) does the + plus operator serve in JavaScript?
to add numeric values or concatenate one string into another
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
group together a set of variables and functions
What are object properties?
variable that is attached to the object and we can store data
Describe object literal notation.
variable, assigning operator , curly braces, and collection of property and values
How do you remove a property from an object?
use the delete keyword followed by the object name and property
What are the two ways to get or update the value of a property?
using dot notation or bracket notation
What are arrays used for?
It stores a list of values
Describe array literal notation.
variable keyword, variable name, assignment operator, square brackets with the values inside separated by a comma
How are arrays different from “plain” objects?
object: Property name and value, array: numeric index and value
What number represents the first index of an array?
0
What is the length property of an array?
The number of items in the array
How do you calculate the last index of an array?
arrayName.length - 1
What is a function in JavaScript?
a procedure—a set of statements that performs a task or calculates a value
Describe the parts of a function definition.
the function keyword
an optional name
zero or more parameters
{a code block
an optional return statement}
Describe the parts of a function call
The function’s name.
() parentheses, with the arguments inside
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition has the function keyword and a block of code. whereas function call has only the function name followed by the parentheses
What is the difference between a parameter and an argument?
Parameters are variables listed as a part of the function definition. · Arguments are values passed to the function when it is invoked.
Why are function parameters useful?
They allow a function to work with different data depending on what values are passed to the function when it is called.
What two effects does a return statement have on the behavior of a function?
exits the function’s code block and returns control to the calling function
Why do we log things to the console?
To see what our data is
What is a method?
A method is a function which is a property of an object.
How is a method different from any other function?
The difference is that a method is associated with an object, while a function is not.
How do you remove the last element from an array?
Using The pop() method
How do you round a number down to the nearest integer?
Math.floor() method
How do you generate a random number?
Math.random() method
How do you delete an element from an array?
Using splice, pop shift slice method
How do you append an element to an array?
Using push or unshift method
How do you break a string up into an array?
Using split(“ “) method
Do string methods change the original string? How would you check if you weren’t sure?
No, they do not. Using console.log
Roughly how many string methods are there according to the MDN Web docs?
50
Is the return value of a function or method useful in every situation?
No
Roughly how many array methods are there according to the MDN Web docs?
40