JavaScript Flashcards
What is the purpose of variables?
To use as an identifier in JavaScript and the variable must be identified with unique names.
How do you declare a variable?
Use var, let (variable with restricted scope), or const (a variable that can’t be reassigned) keyword.
How do you initialize (assign a value to) a variable?
Put variable (name) = (operator) and value. Ex) var a = 1.
What characters are allowed in variable names?
The first character must start with a letter, underscore, or a dollar sign ($), and don’t forget variable names are case-sensitive and don’t use JavaScript’s reserved keywords.
What does it mean to say that variable names are “case sensitive”?
This means that any identifiers should always be typed with consistent character capitalization within acceptable rules.
What is the purpose of a string?
It is used for storing and manipulating text in JavaScript.
What is the purpose of a number?
It is a primitive wrapper object used to represent and manipulate numbers.
What is the purpose of a boolean?
It is used to represent one of two values in a value, such as True or False, Yes or No, and On or Off.
What does the = operator mean in JavaScript?
It performs some operation on single or multiple operands (data values) and produces a result.
How do you update the value of a variable?
Just update the new value under the same variable name or use temporary values.
What is the difference between null and undefined?
They are equal in value (empty value) but different in type. Undefined can exist by itself in JS, but null is not. If you see the null object, that means your existing variable value is reserved for some reason.
Why is it a good habit to include “labels” when you log values to the browser console?
To identify easier, faster, and more directly when you work on some big project or work with coworkers.
Give five examples of JavaScript primitives.
String, number, boolean, null, and undefined. Everything else is an object.
What data type is returned by an arithmetic operation?
It returns a number data type.
What is string concatenation?
It is the process of appending one string to the end of another string.
What purpose(s) does the plus operator (+) serve in JavaScript?
It produces the sum of numeric operands or string concatenation.
What data type is returned by comparing two values (, ===, etc)?
It returns a boolean value.
What does the plus-equals (+=) operator do?
It adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
It holds multiple values in terms of properties and methods in an object.
What are object properties?
It’s a variable that is attached to the object. It is sorted as the same as an ordinary variable except for the attachment to the object.
Describe object literal notation.
var object name = {property name: value of it, another property name: value of it}.
How do you remove a property from an object?
Use delete keyword and the object name.property name or keyword delete object name[‘property name’].
What are the two ways to get or update the value of a property?
Object name.property name = value that you want to update or object name[‘property name’] = value that you want to update.
What are arrays used for?
It is used when you store a collection of variables of the same type.
Describe array literal notation.
var array object name = [‘’, ‘’, ‘’ ];
How are arrays different from “plain” objects?
Objects represent a special data type that is mutable and can be used to store a collection of data. On the other hand, arrays are a special type of variable that is also mutable and can also be used to store a list of values.
What number represents the first index of an array?
0.
What is the length property of an array?
The length property sets or returns the number of elements in that array.
How do you calculate the last index of an array?
the length of the array - 1.
What is a function in JavaScript?
It is a block of code also repeatable to perform a particular task or calculate a value.
Describe the parts of a function definition.
function keyword, named function (optional), parameter (optional, but it should take some input and return output and there is some obvious relationship between them.) inside of the parenthesis, curly brace for the function code block.
Describe the parts of a function call.
the function name, argument inside of the parenthesis.
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition’s meaning is to remember the method of it but stays still. On the other hand, a function call instructs JavaScript to execute the code of the function.
What is the difference between a parameter and an argument?
The parameters are listed inside the parenthesis. The arguments are the values received by the function when it is invoked.
Why are function parameters useful?
Because those are expected to be the same as variables except that the values of these variables are defined when we call the function.
What two effects does a return statement have on the behavior of a function?
It ends the execution of a function and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.
Why do we log things to the console?
It prints the output to the console, so we can see what is going on, and be able to fix the code if something is wrong.
What is a method?
It is a function that is a property of an object.
How is a method different from any other function?
A method is a function that belongs to an object.
How do you remove the last element from an array?
Use array pop() method. name of array.pop();
How do you round a number down to the nearest integer?
Use Math.floor() function.
How do you generate a random number?
Use Math.random() function.
How do you delete an element from an array?
Use splice() method, pop() method, or shift() method (removes the first array).
How do you append an element to an array?
Use unshift() method to add a new element at the beginning, push() method to add a new element at the end, or name of array[index number].
How do you break a string up into an array?
Use the split(‘ ‘) method.
Do string methods change the original string? How would you check if you weren’t sure?
No. Use console.log() or go to read the documentation about it to check.
Is the return value of a function or method useful in every situation?
No. Use when it’s needed.
Give 6 examples of comparison operators.
Strict equal to (===), greater than (>), greater than or equal to (>=), less than or equal to (<=), less than (
What data type do comparison expressions evaluate to?
Boolean: true or false.
What is the purpose of an if statement?
To perform different actions based on different conditions. Use if statement to specify a code to be executed if a specified condition is true.
Is else required in order to use an if statement?
No, it’s not required to write the else part for the if statement.
Describe the syntax (structure) of an if statement.
Keyword if (variable name, comparison, value) { }.
What are the three logical operators?
And (&&), or (||), not (!).
How do you compare two different expressions in the same condition?
Using logical operators (&&, ||, !).
What is the purpose of a loop?
It used to repeatedly run a block of code until a certain condition is met.
What is the purpose of a condition expression in a loop?
It is an expression that is evaluated once before every iteration.
What does “iteration” mean in the context of loops?
It describes going through a set of operations that deal with the code conditions (Each time the code is running).
When does the condition expression of a while loop get evaluated?
When the while loop is created.
When does the initialization expression of a for loop get evaluated?
Very first before anytime.
When does the condition expression of a for loop get evaluated?
Right after the initialization.