JavaScript Flashcards
What is the purpose of variables?
they hold a value and preserve it for future use
How do you declare a variable?
var, let, const
How do you initialize(assign a value to) a variable?
=
What characters are allowed in variable names?
letters, numbers, $, _
What does it mean to say that variable names are “case sensitive”?
need to make sure casing is correct
What is the purpose of a string?
adds new text-value content into a page
What is the purpose of a number?
math use
What is the purpose of a boolean?
making decisions
What does the = operator mean in JavaScript?
making the variable contain value - assign value to a variable
How do you update the value of a variable?
variableName = new value;
What is the difference between null and undefined?
null: intentionally assign it as empty
undefined: does not exist yet
Why is it a good habit to include labels when you log values to the browser console?
To have an immediate reference to what exactly is being logged
Give 5 examples of JavaScript primitives:
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
joining together two or more strings to create one new string
What purpose does the + operator serve in JavaScript?
adds one value to another (math and concatenation)
What data type is returned by comparing two values (, ===, etc..)?
a boolean value - based on whether the comparison is true
What does the += 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 properties and methods to create a model of something you would recognize in the real world
What are object properties?
key/value pairs
Describe object literal notation:
{
key: value (properties),
method: function() {}
};
How do you remove(delete) a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
- dot notation
- square bracket syntax
What are arrays used for?
a list of values that are related to each other
Describe array literal notation:
var arrayName = [‘value’, ‘value’, ‘value’];
How are arrays different than “plain” objects?
- array values are numbered
- the key for each value is its index #, rather than property name
- order matters, whereas order in objects doesn’t
What number represents the first index of an array?
0
What is the length property of an array?
tells us the number of items in the array
- starts count at 1 rather than 0
How do you calculate the last index of an array?
the value of the array’s length property minus 1
What is a function in JavaScript?
a reusable block of code
Describe the parts of a function definition:
function keyword, function name(parameters), {code block}
Describe the parts of a function call:
functionName(arguments);
What are the differences between function definition and a function call?
function definition: has function keyword, parameters, and {code block} function call: functionName followed by arguments in parenthesis
Why do we log things to the console?
to verify expected output and see changes over time
What is a method?
a function stored in a property of an object
How is a method call different from any other function?
you need to specify what object they are coming from
- object.method()
How do you remove the last element of an array?
.pop()
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
Math.random()
How do you delete an element from an array?
.splice()
How do you append an element to an array?
.push()
How do you break a string up into an array?
.split(‘ ‘)
Do string methods change the original string? How would you check?
No - strings cant change.
console.log()
Is the return value of a function or method useful in every situation?
No - sometimes you just want it to do what it does
What 3 letter acronym should you always include in your google search about a JavaScript method or CSS property?
MDN
Give six examples of comparison operators:
> , =, <=, ===, !==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
checks if a condition is true, then executes code in the code block
Is else required in order to use an if statement?
No
Describe the syntax of an if statement
if, (condition), conditional code block