Javascript Flashcards
What is the purpose of variables?
to store date, to call upon the value later.
How do you declare a variable?
you would write the var then variable name , or identifier. If it has more than one name, it is written in camelCase
[var name:]
How do you initialize (assign a value to) a variable?
you would write the identifier then the variable value;
[name = 420;]
What characters are allowed in variable names?
letters,numbers, dollar sign($) or and underscore.
What does it mean to say that variable names are “case sensitive”?
It needs to be written exactly how it is typed. meaning
thisVariable is not the same as thisvariable
What is the purpose of a string?
to give values that contain letters or other characters.
What is the purpose of a number?
to give a numerical value to a variable. Normally for it use as counting/mathematics.
What is the purpose of a boolean?
to define the var as a true/false value.
What does the = operator mean in JavaScript?
it is the assignment operator. it gives us the ability to assign a value to the variable.
How do you update the value of a variable?
you reassign the variable. you wont need to use the var to reassign the variable.
What is the difference between null and undefined?
null is an intentionally nonexistent or invalid object, while undefined has no given value at all, or unintentional.
Why is it a good habit to include “labels” when you log values to the browser console?
It helps identify what the value is related to, if there is no tag. It will just give out the string/value with no context.
Give five examples of JavaScript primitives
String, number, boolean, undefined, and null.
What data type is returned by an arithmetic operation?
a number value
What is string concatenation?
to join to variables into one.
var fullName = firstName + lastName;
What purpose(s) does the + plus operator serve in JavaScript?
It is used to add one value to another
What data type is returned by comparing two values (, ===, etc)?
boolean; true or false
What does the += “plus-equals” operator do?
It lets us add two values together, the result will then be assigned.
What are objects used for?
Objects are for RELATED data.
What are object properties?
A key value pair, a piece of data that is attached under an object with a unique name. The value may change, but the name will stay the same.
Describe object literal notation
You need { }, to store value, you need property name:(value)
How do you remove a property from an object?
use the delete
What are the two ways to get or update the value of a property?
use dot notation or bracket notation.
dot
object.property = (new value);
bracket
object[‘property’] = (new value);
Describe array literal notation.
a variable will x amount of values separated by commas (usually in the same line)
you can store strings, numbers, and booleans
How are arrays different from “plain” objects?
arrays has data is relatable to one another, for example colors. Objects have relatable data to a certain object. (name, height, weight, occupation etc)
What number represents the first index of an array?
the first array value is INDEX 0 (zero)
It starts at zero because it the first item is zero index’s away from the BEGINNING of the array.
What is the length property of an array?
it will show how many Items are within each array.
for example:
var colors = [“white”, “black, “brown”, “green”]
has 4 items in. So:
numColors = colors.length;
should equal numColors = 4;
How do you calculate the last index of an array?
(# of items in array) - 1
Describe the parts of a function definition.
the [function] keyword an optional name a comma-separated list of zero or more parameters. start of the functions' code block' the end of the function's code block
function example(parameter 1, parameter 2....) { //....more javascript code... return; }
Describe the parts of a function call.
function name comma separated list of zero or more arguments
sayHello ();
When comparing them side-by-side, what are the differences between a function call and a function definition?
describing the function is creating the function and what it will do. Calling the function will practically “using” the function only.
What is the difference between a parameter and an argument?
parameter is a placeholder, it is variable that is unknown until we call the function.
A argument is the value that replaces the parameter value in the function.
Why are function parameters useful?
the parameters will let us change the value of the arguments when we call the function
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a new value.
prevents any more code in the function’s code block from being run.
Why do we log things to the console?
to test out our code and to see if it runs properly.
What is a method?
a function which is a property of an object.
console.log is a method. it belongs to the object, console.
How is a method different from any other function?
a method is attached to a object.
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?
you use the Math.floor()
How do you generate a random number?
you use Math.random();