javascript Flashcards
What is the purpose of variables?
The purpose of variables is to store data
How do you declare a variable?
var
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
letters numbers dollarsign and number not at beggining
What does it mean to say that variable names are “case sensitive”?
variables with different cases are different variables
What is the purpose of a string?
The purpose of a string is to store text data
What is the purpose of a number?
The purpose of a number is to store numbers, and perform math.
What is the purpose of a boolean?
The purpose of a boolean is to denote if something is true or false
What does the = operator mean in JavaScript?
the equals operator assigns a value to a variable
How do you update the value of a variable?
You update the value of a variable by using the = sign
What is the difference between null and undefined?
null is assigned on purpose, undefined is not assigned on purpose
What is string concatenation?
The operation of combining strings into one single string
What data type is returned by comparing two values (,===,etc)?
Boolean
What does the += “plus equals” operator do?
It adds a value to a variable. It acts as a shorthand for var = var + value
What are objects used for?
For storing different but related pieces of data, and functions to perform operation on related data.
What are object properties?
Object properties are variables belonging to an object
Describe object literal notation.
Object literal notation is a way of defining an object in javascript.
How do you remove a property from an object?
the delete operator
What are two ways to get or update the value of a propery?
bracket notation and dot notation
What are arrays used for?
Arrays are used for storing data in an indexed format
Describe array literal notation
Array literal notation is a way to describe arrays in your code
How are arrays different from “plain” objects”
Arrays are indexed
What number represents the first index of an array?
0
What is the length property of an array?
it gives the number of values in the array
How do you calculate the last index of an array
you take the length property and subtract it by one.
What is a function in JavaScript?
A function is a block of code that can be run, and have values passed in, and out.
Describe the parts of a function definition.
The function name, the function code block, the function return, the function parameters.
Describe parts of a function call.
the function name, the function arguments.
When comparing them side-by-side, what are the differences between a function call and a function definition?
The function definition has a code block and can have a return statement, the function call has parameter values for arguments.
What is the difference between a parameter and an argument?
A parameter describes content that will be passed at some point into a function, an argument is a value being passed into a method we are calling.
Why are function parameters useful?
They help us pass data into functions so that they can be self contained (scope)
What two effects does a return statement have on the behavior of a function?
It returns a value, and stops code execution of the function code block.
Why do we log things to the console?
To debug our code
What is a method?
a method is a function belonging to an object
How is a method different from any other function?
a method is different because it is called from a function using dot notation
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()