JavaScript Flashcards
JavaScript-Primitives-and-Variables
What is the purpose of variables?
To store data or information so that we can use those data or information later.
JavaScript-Primitives-and-Variables
How do you declare a variable?
Write a variable keyword and a variable name. For example, var FullName;
JavaScript-Primitives-and-Variables
How do you initialize (assign a value to) a variable?
Use the equal sign(=) as an assignment operator
JavaScript-Primitives-and-Variables
What characters are allowed in variable names?
The name can contain letters, numbers, dollar sign($) or an underscore. But you cannot start with numbers.
JavaScript-Primitives-and-Variables
What does it mean to say that variable names are “case sensitive”?
If two variables are the same words but one has upper-case and other one has lower-case, it becomes different variables.
JavaScript-Primitives-and-Variables
What is the purpose of a string?
Strings can be used when working with any kind of text
JavaScript-Primitives-and-Variables
What is the purpose of a number?
Numbers can be used to calculate, determine the size of the screen, moving the position of an element on a page or setting the amount of time an element should take to fade in.
JavaScript-Primitives-and-Variables
What is the purpose of a boolean?
-To make decisions. For example, yes or no, turn switch on or off.
JavaScript-Primitives-and-Variables
What does the = operator mean in JavaScript?
is assignment operator. Assign value to the variable
JavaScript-Primitives-and-Variables
How do you update the value of a variable?
Assign new variable value
JavaScript-Primitives-and-Variables
What is the difference between null and undefined?
undefined means that the property has not been defined yet. Whereas, null means that the property has been defined but is empty. Null is intentionally not defined value. For example, null is like a parking lot where you can fill it in later, and undefined is an empty field.
JavaScript-Primitives-and-Variables
Why is it a good habit to include “labels” when you log values to the browser console?
Help others and myself where these values are coming from. Benefit others and yourself in the future
JavaScript-Primitives-and-Variables
Give five examples of JavaScript primitives.
Null, String, Number, Boolean, undefined
JavaScript-Operator-and-expressions
What data type is returned by an arithmetic operation?
Number
JavaScript-Operator-and-expressions
What is string concatenation?
Combine two or more strings to create one new string
JavaScript-Operator-and-expressions
What purpose(s) does the + plus operator serve in JavaScript?
Add one value to another or concatenate strings
JavaScript-Operator-and-expressions
What data type is returned by comparing two values (, ===, etc)?
Boolean
JavaScript-Operator-and-expressions
What does the += “plus-equals” operator do?
It is the additional assignment operator that adds the value of the right operand to a variable and assigns the result to the variable.
JavaScript-Objects
What are objects used for?
Associated with information to describe to a group of a lot of information together
The object is to model a real-world object.
JavaScript-Objects
What are object properties?
Key and value
Variables attached to an object
JavaScript-Objects
Describe object literal notation.
Variable keyword, variable name, assignment operator, opening curly brace, key and values and closing curly brace.
JavaScript-Objects
How do you remove a property from an object?
Use the delete keyword. For example, delete hotel.name;
JavaScript-Objects
What are the two ways to get or update the value of a property?
Use dot notation or square brackets
JavaScript-Arrays
What are arrays used for?
To store a list of values
JavaScript-Arrays
Describe array literal notation.
var keyword, variable name, assignment operator, and values in the opening and closing square brackets
JavaScript-Arrays
How are arrays different from “plain” objects?
Array can use an index number to access a specific item
JavaScript-Arrays
What number represents the first index of an array?
Zero
JavaScript-Arrays
What is the length property of an array?
Number of items in the array
JavaScript-Arrays
How do you calculate the last index of an array?
Array.length - 1; Object at lengths of Array -1
JavaScript-functions
What is a function in JavaScript?
Functions are objects that are reusable
JavaScript-functions
Describe the parts of a function definition.
Function keyword, optional name, zero or more parameters, opening and closing curly braces for the function’s code block, and optional return statement
JavaScript-functions
Describe the parts of a function call.
Function’s name and list of arguments surrounded by parenthesis
JavaScript-functions
When comparing them side-by-side, what are the differences between a function call and a function definition?
When function is called, the parameters in its definition take on the values of the arguments that were passed.
JavaScript-functions
What is the difference between a parameter and an argument?
A parameter is a placeholder that we don’t know the value of until we call it.
Arguments are the values that are given to the function
Parameters are the local variables.
When we call the function, the parameter becomes an argument.
When we define a function, we declare parameters, and when we call a function, we pass it arguments.
JavaScript-functions
Why are function parameters useful?
The parameter can hold the value of the argument until it is called.
JavaScript-functions
What two effects does a return statement have on the behavior of a function?
The return statement causes the function to produce a value
The return statement exits the function’s code block
JavaScript-methods
Why do we log things to the console?
The console is a debugging tool where the browser prints error and warnings as they occur in JavaScript code. (debugging mechanism)
JavaScript-methods
What is a method?
A method is a function which is a property of an object.
JavaScript-methods
How is a method different from any other function?
The method is associated with an object while a function is not
JavaScript-methods
How do you remove the last element from an array?
pop() method
JavaScript-methods
How do you round a number down to the nearest integer?
Math.floor()
JavaScript-methods
How do you generate a random number?
Math.random()
JavaScript-methods
How do you delete an element from an array?
splice()
JavaScript-methods
How do you append an element to an array?
push()
JavaScript-methods
How do you break a string up into an array?
Split() method.
JavaScript-methods
Do string methods change the original string? How would you check if you weren’t sure?
No, use console log to find out if string methods changed the original string
JavaScript-methods
Roughly how many string methods are there according to the MDN Web docs?
Around 45
JavaScript-methods
Is the return value of a function or method useful in every situation?
No
JavaScript-methods
Roughly how many array methods are there according to the MDN Web docs?
Around 45 to 50
JavaScript-methods
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
JavaScript-if
Give 6 examples of comparison operators.
Is equal to (==), is not equal to (!=), strict equal to (===), strict not equal to (!==), Greater than(>), less than (<>, greater than or equal to (>=), less than or equal to (<=)
JavaScript-if
What data type do comparison expressions evaluate to?
Boolean
JavaScript-if
What is the purpose of an if statement?
The if statement evaluates (or checks) a condition. If the condition evaluates to true, any statements in the subsequent code block are executed.
JavaScript-if
Is else required in order to use an if statement?
No
JavaScript-if
Describe the syntax (structure) of an if statement.
Keyword if, condition opening and code inside the closing curly braces and
JavaScript-if
What are the three logical operators?
Logical AND (&&), Logical OR (||), Logical NOT(!)
JavaScript-if
How do you compare two different expressions in the same condition?
Use logical operators
JavaScript-loops
What is the purpose of a loop?
To repeat the similar or the same code over time. To repeat the code without writing it out all ourselves.
JavaScript-loops
What is the purpose of a condition expression in a loop?
To check if the condition is true so that the statement can be executed.
JavaScript-loops
What does “iteration” mean in the context of loops?
Iteration is the number of times a loop can be executed
JavaScript-loops
When does the condition expression of a while loop get evaluated?
An expression is evaluated before each pass through the loop.
JavaScript-loops
When does the initialization expression of a for loop get evaluated?
An expression or variable declaration is evaluated once before the loop begins.
JavaScript-loops
When does the condition expression of a for loop get evaluated?
An expression is evaluated before each loop iteration.
JavaScript-loops
When does the final expression of a for loop get evaluated?
An expression is evaluated at the end of each loop iteration. This occurs before the next evaluation of the condition.