JavaScript Flashcards
JavaScript Primitives and Variables
What is the purpose of variables?
To store data so that we can go back to variables later
JavaScript Primitives and Variables
How do you declare variable?
Create the variable name and give it a name.
Ex) var name
JavaScript Primitives and Variables
How do you initialize (assign a value to) a variable?
The equal sign (=) is an assignment operator. It says that you are going to assign a value to the variable. It also used to update the value given to a variable
ex) var keyword variable name = value
JavaScript Primitives and Variables
What characters are allowed in variable names?
A letter, dollar sign($) or an underscore(_). It must not start with a number
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.
storage for characters
JavaScript Primitives and Variables
What is the purpose of a number?
To count or calculate sums and store numeric values
JavaScript Primitives and Variables
What is the purpose of a boolean?
To make decisions. For example, yes or no
JavaScript Primitives and Variables
What does the = operator mean in JavaScript?
It 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 is empty for some reason but we don’t know why it is empty. Undefined is a computer (JavaScript) saying nothing. cannot tell which said undefined.
- Null is assigned by humans, not JavaScript.
- Null is an empty value that needs to be assigned at some point. It made the empty on purpose to put values later.
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
Undefined, null, number, string, boolean
JavaScript Operators and Expressions
What data type is returned by an arithmetic operation?
Numeric/Number
JavaScript Operators and Expressions
What is string concatenation?
Join two or more strings to create one new string
JavaScript Operators and Expressions
What purpose(s) does the + plus operator serve in javaScript?
Add one value to another
The additional operator (+) produces the sum of numeric operands or string concatenation.
JavaScript Operators and Expressions
What data type is returned by comparing two values(, ===, etc)?
boolean
JavaScript Operators and Expressions
What does the += ‘plus-equals’ operator do?
Value on the right side added to the left variable, and then get new value.
JavaScript Objects
What are objects used for?
Group of data and functionality.
Data type to store further data with individual properties.
JavaScript Objects
What are object properties?
Individual key correlates with value
JavaScript Objects
Describe object literal notation
opening and closing curly braces
JavaScript Objects
How do you remove a property from an object?
Delete operator and name of object.property
JavaScript Objects
What are the two ways to get or update the value of a property?
To update the value of properties, use dot notation or square brackets.
JavaScript Arrays
What are arrays used for?
list of data
JavaScript Arrays
Describe array literal notation
opening and closing square brackets.
JavaScript Arrays
How are arrays different from “plain” objects?
An Array does not need an individually named key. Only numbers.
Objects can have numbers and letters
The array is made with property length.
The array counts the total number of items.
Object has to state the name directly.
The Array can use unshift, push method to interact
JavaScript Arrays
What number represents the first index of an array?
Zero
JavaScript Arrays
What is the length property of an array?
Holds the number of items in the array
Tells you how many items are in the array
JavaScript Arrays
How do you calculate the last index of an array?
Object at lengths of Array -1 ex) students[length of Array -1] -> student[array.length -1]
JavaScript Functions
What is a function in JavaScript?
- A set of statements that perform a task or calculate a value
- Functions are objects that are reusable.
JavaScript Functions
Describe the parts of a function definition.
The function keyword, the name of function, a list of parameters to the function, enclosed in parenthesis and separated by commas, and the JavsScript statements that define function, enclosed in curly braces { }.
JavaScript Functions
Describe the parts of a function call.
Write the name of the function and zero or more arguments with a comma surrounded by parenthesis ().
JavaScript Function
When comparing them side-by-side, what are the differences between a function call and a function definition?
When a function is called, the parameters in its definition take on the value of the arguments that were passed.
JavaScript Function
What is the difference between a parameter and an argument?
A parameter is like a placeholder.
When considering an actual “call” to the function, it becomes an argument.
-When we define a function, we declare parameters and that when we call a function, we pass it arguments.
JavaScript Function
Why are function parameters useful?
The parameter can hold the value of the argument until it is called.
Varying results based on data we give. The parameter is reusable.
JavaScript Function
What two effects does a return statement have on the behavior of a function?
Cause 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. (Exit the function; no code after the return statement is executed.)
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 other function is not.
JavaScript - Methods
How do you remove the last element from an array?
the pop() method
JavaScript - Methods
How do you round a number down to the nearest integer?
the math.floor() method
JavaScript - Methods
How do you generate a random number?
the math.random() method
JavaScript - Methods
How do you delete an element from an array?
the splice() method
JavaScript - Methods
How do you append an element to an array?
the push() method
JavaScript - Methods
How do you break a string up into an array?
the split() method
Do string methods change the original string? How would you check if you weren’t sure?
No. String is immutable so it would not change. Inspect your value using console.log to check if you are not sure.
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 a method useful in every situation?
No
JavaScript - Methods
Roughly how many array methods are there according to the MDN Web docs?
Around 40 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
Greater than (>), less than (=), less than or equal to (<=), is equal to (==), is not equal to (!=), strictly equal to (===), strict not equal to (!==),
JavaScript-if
What data type do comparison expressions evaluate to?
Boolean
JavaScript-if
What is the purpose of an if statement?
To evaluate or check a condition and make decisions.
JavaScript-if
Is else required in order to use an if statement?
No
JavaScript-if
Describe the syntax (structure) of an if statement.
KEY word if, condition, Opening curly brace ({), code to execute if value is true, closing curly brace(}).
JavaScript-if
What are the three logical operators?
The logical AND (&&), logical OR (||) and logical NOT (!)
JavaScript-if
How do you compare two different expressions in the same condition?
Use the logical operators
JavaScript-loop
What is the purpose of a loop?
To repeat the similar or the same code over time and to repeat the code without writing out all ourself
JavaScript-loop
What is the purpose of a condition expression in a loop?
Stop to not fall into the infinity loop
JavaScript-loop
What does “iteration” mean in the context of loops?
How many times the loop will go through
JavaScript-loop
When does the condition expression of a while loop gets evaluated?
before each iteration
JavaScript-loop
When does the initialization expression of a for loop gets evaluated?
An expression or variable declaration that evaluated once before the loops begin.
JavaScript-loop
When does the condition expression of a for loop gets evaluated?
An expression to be evaluated before each loop iteration. If it evaluates to true, statement is executed. If it is false, the loop stops
JavaScript-loop
When does the final expression of a for loop gets evaluated?
An expression to be evaluated at the end of each loop iteration. After the code block runs. before condition runs again.
JavaScript-loop
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break