Module 1 Javascript Flashcards
What is the purpose of variables?
It tells the script to store information to be used again later.
How do you declare a variable?
declare var, let, or const. Can be declared undefined or can have value assigned initially.
How do you initialize (assign a value to) a variable?
Use equal sign =
What characters are allowed in variable names?
Must start with any letter, dollar sign $, or underscore _, numbers as long as it is not the first letter, no - or .
What does it mean to say that variable names are “case sensitive”?
Capitalization matters in variable name
What is the purpose of a string?
String stores a series of letters or other characters, used for adding text.
What is the purpose of a number?
Store numerical values.
What is the purpose of a boolean?
Booleans store a true or false value.
What does the = operator mean in JavaScript?
single equal sign = is for assigning values.
How do you update the value of a variable?
state variableName = newValue; Reassign, not redeclare.
What is the difference between null and undefined?
Null represents an nonexistend or invalid object. Undefined means nothing has been declared or assigned, so there is nothing, not even an object.
Why is it a good habit to include “labels” when you log values to the browser console?
Helps you debug so you know at which step and for what reason the console is logged.
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined.
What data type is returned by an arithmetic operation?
A number
What is string concatenation?
Combining two or more strings into one string. Numbers concatenated with strings also become a string.
What purpose(s) does the + plus operator serve in JavaScript?
It can both add numbers as an operator and concatenate strings.
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Adds the value to the right and assigns it to the variable on the left.
What are objects used for?
Grouped set of property variables to create a model of a real world object.
What are object properties?
The variables within the object
Describe object literal notation.
the object name is being declared and assigned with opening curly brace, within are key values and property pairs separated by commas, and closing curly brace.
How do you remove a property from an object?
Use delete keyword and call out the object property using either dot or bracket notation.
What are the two ways to get or update the value of a property?
Name the object property using either dot or bracket notation, and assign a new value if desired.
What are arrays used for?
To have an ordered list of items
Describe array literal notation.
The array name being declared and assigned with an opening bracket, a list of values separated by commas, and a closing bracket.
How are arrays different from “plain” objects?
Array values are numerically indexed.
What number represents the first index of an array?
0
What is the length property of an array?
The number of values the array contains
How do you calculate the last index of an array?
Take the array.length - 1
What is a function in JavaScript?
Pack up a dynamic code that can be reused to do something within javascript. Or- set of instructions that we can call again at any time.
Describe the parts of a function definition.
function name, function parameters, function codeblock with opening and closing curly braces, return statement within codeblock.
Describe the parts of a function call.
Function name with the parentheses and parameters within if applicable.
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition sets up the code for the function to run when it is called, but does not run it. Function call runs the code within the definition.
What is the difference between a parameter and an argument?
Parameters are placeholders for arguments to be used, arguments are what the code actually uses.
Why are function parameters useful?
They let you hold the place of future unknown arguments to be used.
What two effects does a return statement have on the behavior of a function?
It tells the function to produce a value, prevents anything else after in the function code from being run, and exits the function codeblock.
Why do we log things to the console?
To help keep track of what is going on in the code and help with debugging
What is a method?
Functions that are properties of an object
How is a method different from any other function?
They are stored within and called from an object. They are attached to an object.
How do you remove the last element from an array?
use array.prototype.pop() method.
How do you round a number down to the nearest integer?
use Math.floor(#) method.
How do you generate a random number?
use Math.random() method. Only generates between 0 and 1, 0 and 1 not inclusive.
How do you delete an element from an array?
use array.prototype.splice(index, deleteCount)
How do you append an element to an array?
Use array.prototype.push() method to end, unshift to push to front.
How do you break a string up into an array?
Use string.prototype.split() method.
Do string methods change the original string? How would you check if you weren’t sure?
No, and you can check with console.log(). Note strings are immutable, they cannot be changed.
Roughly how many string methods are there according to the MDN Web docs?
38 (Just note that there are more than 30 and it can be looked up)
Is the return value of a function or method useful in every situation?
No. Note keyword ‘every’, not always have to be returned. For example, pop method just used to remove something from array but you don’t use what is popped.
Roughly how many array methods are there according to the MDN Web docs?
36 (Just note that there are more than 30 and it can be looked up)
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
===, >=, <=, =, !==
What data type do comparison expressions evaluate to?
boolean value (true or false)
What is the purpose of an if statement?
Sets up conditional statement and tells it run if true.
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if (condition) {code}
What are the three logical operators?
and &&, or ||, not !
How do you compare two different expressions in the same condition?
Use logical operator to use both expressions
What is the purpose of a loop?
To repeat a code multiple times as needed