JavaScript Flashcards
What is the purpose of variables?
to store data/ information that the script will use later
How do you declare a variable?
var, let, const
How do you initialize (assign a value to) a variable?
var variableName = value;
What rules are allowed in naming variable names?
must begin with letter, $, or _ and must NOT start with a number
can contain characters above but not - or .
cannot use existing keywords like var
case sensitive
camel case
What does it mean to say that variable names are “case sensitive”?
score != Score
What is the purpose of a string?
to include text data such as names… etc characters
What is the purpose of a number?
to store numerical data, integers…. decimals..
What is the purpose of a boolean?
to store logical data, true false, 1 and 0,
What does the = operator mean in JavaScript?
assignment operator, assigns value to variables
How do you update the value of a variable?
by recalling the variable name and assigning with a new value after the first assignment line
var number = 1;
number = 2;
console.log(number)
>2
What is the difference between null and undefined?
difference is that null is derived from an object and points to non-existent/ invalid object
undefined is a value assigned to variables that have not been assigned a value
null says the there is no box in existence, undefined says the box is empty
null is assigned to be empty on purpose –> “empty”
never assign anything with undefined
Why is it a good habit to include “labels” when you log values to the browser console?
to specify what the varible the input is coming from
Give five examples of JavaScript primitives.
number string boolean null undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining string values using + arithmetic operator
What purpose(s) does the + plus operator serve in JavaScript?
addition operator and string concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
addition assignment, adds left side to value to variable current value.
What are objects used for?
objects are used to provide properties or characteristics to one ‘object’
What are object properties?
variables of that object that describe a value
Describe object literal notation.
{ property: value, …. }
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
object.property = new value object['property'] = new value
What are arrays used for?
to store a list of items or objects
Describe array literal notation.
[value, value, value]
How are arrays different from “plain” objects?
ordered, the property of arrays is its index
What number represents the first index of an array?
0
What is the length property of an array?
How do you calculate the last index of an array?
array.length gives length of array
array[array.length - 1]
What is a function in JavaScript?
a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output
allow you to package up code for use later in your program
Describe the parts of a function definition.
Describe the parts of a function call.
function functionName (parameters) { code block }
functionName(argument)
When comparing them side-by-side, what are the differences between a function call and a function definition?
call does not have code blocks just an argument
What is the difference between a parameter and an argument?
when defining a function you call parameters but when you call a function you define arguments.
Why are function parameters useful?
because it is like a placeholder until a variable is passed through an argument and the function is called
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value we can use in our program.
Prevents any more code in the function’s code block from being run.
Why do we log things to the console?
to print value of a variable to the console and is used as sa debuggin tool
What is a method?
a function that is a property of an object
How is a method different from any other function?
it is a property that comes from that object/array constructor so that any object/array created will have that method used
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( )