JavaScript Flashcards
What is the purpose of variables?
Variables are used to store data that can be referenced and/or changed later on.
How do you declare a variable?
You can declare a variable using var (global scoped) or let, const (block scoped).
How do you initialize (assign a value to) a variable?
You assign a value to a variable using =
What characters are allowed in variable names?
Variables must start with a letter, underscore, or $ sign. You may not use any JavaScript keywords.
What does it mean to say that variable names are “case sensitive”?
This means that the variable names must always be typed with consisted capitalization of characters. Otherwise, they will be treated as different variables entirely.
What is the purpose of a string?
A string is used to store and manipulate text.
What is the purpose of a number?
JavaScript numbers are used to store numerical values as double precision floating point numbers
What is the purpose of a boolean?
Boolean variables are used to store a value of true or false, and are often used to evaluate the truth of an expression.
What does the = operator mean in JavaScript?
It is the assignment operator that is used to store the operand on the right side to the operand on the left side.
How do you update the value of a variable?
There are various ways to update the value of a variable. Besides the assignment operator, we can use +=, -=, *=. /=
What is the difference between null and undefined?
Null is an assigned value that means nothing. Undefined means that the variable has been declared but not defined yet.
Why is it a good habit to include “labels” when you log values to the browser console?
It is a good practice to include labels as it allows the developer to know exactly context of the data being displayed.
Give five examples of JavaScript primitives.
Undefined, null, boolean, number, string
What data type is returned by an arithmetic operation?
If both operands are numerical data, the operation will result in numerical data. However, if an operand is a string, then operation will result in a string.
What is string concatenation?
The arithmetic operation of two string operands.
What purpose(s) does the + plus operator serve in JavaScript?
The + operator is used to add operands on the left and right side of the operator.
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
The += operator adds the value of the right operand with the left operand and stores the result in the left operand.
What does the += “plus-equals” operator do?
The += operator adds the value of the right operand with the left operand and stores the result in the left operand.
What are objects used for?
An object is a self-contained component with its own properties, functions, and data structures. They are used to encapsulate their own actions from the rest of the program.
What are object properties?
Properties are values associated with a JavaScript object. Properties are in the form of key:value
Describe object literal notation.
The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array.
How do you remove a property from an object?
By using the delete operator.
What are the two ways to get or update the value of a property?
By using the dot nation or bracket notation
myCar.make
myCar[‘make’]
What are arrays used for?
An array allows for a collection of multiple items under a single variable name.
Describe array literal notation.
An array literal is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ( [] ).
How are arrays different from “plain” objects?
An array is used to store multiple items under a single variable. An object is used to contain self-related items under a single object name.
What number represents the first index of an array?
0
What is the length property of an array?
The amount of items stored in the array.
How do you calculate the last index of an array?
By placing length-1 in the index.
What is a function in JavaScript?
A function is a block of instructions that accomplished a certain task (described by the name of the function).
Describe the parts of a function definition.
function keyword optional name opening curly bracket code block return value closing curly bracket
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function call causes the function code to execute. A function definition simply lays out the steps but doesn’t cause code to execute.
What is the difference between a parameter and an argument?
A parameter is used as an input in a function definition. An argument is used as input in a function call.
Why are function parameters useful?
They allow the function to be reusable with a variety of arguments.
What two effects does a return statement have on the behavior of a function?
The return statement ends the execution of the function and returns the value to the caller.
Why do we log things to the console?
We log to the console so we know what the code is doing. This ensures that the code is functioning as intended.
What is a method?
A method is a property of an object that contains a function definition.
How is a method different from any other function?
A method is associated with an object while a function is not.
How do you remove the last element from an array?
pop() method
How do you round a number down to the nearest integer?
You use the Math.floor() method.
How do you generate a random number?
Math.method() function
How do you delete an element from an array?
splice() method
How do you append an element to an array?
push() method
How do you break a string up into an array?
split() method
Do string methods change the original string? How would you check if you weren’t sure?
No, they
Roughly how many string methods are there according to the MDN Web docs?
According to MDN, there are roughly 50 string methods.
Is the return value of a function or method useful in every situation?
No, it certain situations, the return value is irrelevant to the functionality.
Roughly how many array methods are there according to the MDN Web docs?
There are roughly 41 array methods.
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
What is the purpose of an if statement?
To execute code if a condition is met.
Is else required in order to use an if statement?
No, not all if statements need an else statement.
Describe the syntax (structure) of an if statement.
if conditional keyword (........) conditional expression { opening curly brace code block } closing code block
What are the three logical operators?
&& (AND), || (OR), ! (NOT)