JavaScript Flashcards
What is the purpose of variables?
To store data needed for a script to do its job.
How do you declare a variable?
Variables are declared by writing the var keyword and variable name followed by a semicolon.
How do you initialize (assign a value to) a variable?
Variables are initialized by writing the assignment operator and value after the variable name.
What characters are allowed in variable names?
Letters, numbers, underscores (_), and dollar signs ($).
What does it mean to say that variable names are “case sensitive”?
Variable names that consist of the same characters but different capitalization are distinct (not the name).
(Also, capitalization should be consistent.)
What is the purpose of a string?
The purpose of a string is to store text (any set of characters).
What is the purpose of a number?
The purpose of a number is to store numerical values.
What is the purpose of a boolean?
The purpose of a boolean is to express true or false statements (decision making).
What does the = operator mean in JavaScript?
The = operator in Javascript means assignment (of a value or return to a variable).
How do you update the value of a variable?
Variables are updated by writing the variable name and assignment operator followed by the new value and semicolon.
What is the difference between null and undefined?
Null represents a nonexistent object (an intentional placeholder for “empty”).
Undefined is automatically assigned to variables that have just been declared (JavaScript’s way of saying a variable is empty - does not have access/cannot create null).
Developers should not used undefined.
Why is it a good habit to include “labels” when you log values to the browser console?
Labels assist with referencing what a value represents or where it is from in the code.
Give five examples of JavaScript primitives.
String, Number, Boolean, Null, and Undefined.
(Also Big Int and Symbol)
What data type is returned by an arithmetic operation?
An arithmetic operation returns a number.
*NaN - not a number (typeof number)
What is string concatenation?
String concatenation is joining two or more strings or characters.
Immutable - Unable to be mutated/changed
What purpose(s) does the + plus operator serve in JavaScript?
The plus operator in JavaScript is used for either addition for arithmetic operations or concatenation for joining strings or characters.
What data type is returned by comparing two values (<, >, ===, etc)?
Comparing two values returns the Boolean data type.
What does the += “plus-equals” operator do?
The plus-equals operator adds the value from the right side of the operator to the left side of the operator.
(x += 1; is the shorthand version of x = x + 1;)
What are objects used for?
Objects are used for grouping together a set of variables and functions to represent something in the real world.
What are object properties?
Object properties are variables that are part of an object.
Describe object literal notation.
A comma-separated list of key-value pairs inside curly braces.
How do you remove a property from an object?
Properties are removed from an object by writing the delete operator/keyword followed by the object name an property name.
What are the two ways to get or update the value of a property?
The two ways to get or update the value of a property are dot notation or bracket notation.
What are arrays used for?
Arrays are used for listing a set of values that are related to each other.
Describe array literal notation.
A comma-separated list of values between square brackets.
How are arrays different from “plain” objects?
The key for each value in an array is its index number instead of a property.
Values are added to arrays using methods.
Arrays have a length property.
What number represents the first index of an array?
Zero.
What is the length property of an array?
The length property returns the number of characters in a string or the number of elements in an array.
How do you calculate the last index of an array?
The last index of an array is calculated by evaluating the length property of the array minus one.
What is a function in JavaScript?
A set of statements that performs a task or calculates a value. Functions are reusable and can be written once to handle many situations.
Describe the parts of a function definition.
- The function keyword
- A function name (optional)
- A comma-separated list of parameters surrounded by parenthesis
- Start of the function’s code block
- A return statement (optional)
-The end of the function’s code block