JavaScript Flashcards
What is the purpose of variables?
To store, represent, and access data via an easily accessible name called an identifier.
How do you declare a variable?
var keyword, or in ES6: let and const keywords.
How do you initialize a variable?
Using the assignment operator = followed by the value, followed by a semi-colon.
What characters are allowed in variable names?
Letters, numbers, dollar sign, or an underscore.
Cannot begin with a number.
Notes: Using the underscore is not very common in JavaScript, but a convention among professional programmers is to use it as an alias for “private (hidden)” variables.
Using the $ is not too common, but professional programmers often use it as an alias for the main function in a JavaScript library or using them for variables holding DOM elements. In jQuery, for instance, the main function $ is used to select HTML elements. In jQuery $(“p”); means “select all p elements”.
What does it mean to say that variable names are “case sensitive”?
That changing the case of a letter in a declared variable name will not access the value. The memory address for a variable is assigned to the identifier using the case the declaration was made it. Guidelines state to use camelCase.
What is the purpose of a string?
For storing and manipulating a sequence of characters or text
What is the purpose of a number?
To store and manipulate numerical values and to do math, more precisely 64 bit floating point numbers (up to 15 digits and 17 decimals), positive and negative infinity, and NaN.
What is the purpose of a boolean?
To find out if an expression or a variable is true or false or when you need a data type that can only have two values, like on and off. Used for comparisons and for decision-making in a program (conditionals).
What does the = operator mean in JavaScript?
It’s an assignment operator, it assigns value to a variable
How do you update the value of a variable?
Using the assignment operator, math functions or other methods, or changing property values
What is the difference between null and undefined?
Undefined is the absence of data, no value is assigned, is falsy.
Null is the intentional absence of data, treated as a falsy value. Usually a placeholder for data that later gets created or added.
Why is it a good habit to include “labels” when you log values to the browser console?
It describes the value being logged, it can help with debugging by adding clarity to what you’re looking at and what’s happing in your script.
What are the 7 JavaScript primitive data types.
string, number, boolean, undefined, null, bigint, and symbol
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
It’s the operation of joining strings together, which can be done with the addition operator or a template literal – or you can cheat with just using a comma between strings, lol.
What purpose(s) does the + plus operator serve in JavaScript?
Concatenation, addition, and the unary plus operator converts its operand to Number type.
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
It adds the value to the right of the addition assignment operator to the variable and then assigns the result of the expression to that variable
What are objects used for?
To store a group of key/value pairs and methods as a single entity, or model, as Duckett describes it.
What are object properties?
Variables that store some related data about the object, often referred to as key/value pairs.
Describe object literal notation.
Variable declaration or identifier for the for the object, then wrapped in curly braces, property or keys and values separated by a colon, multiple key/value pairs are separated by commas.
ex: var objectName = {
property: value,
property: value
}
How do you remove a property from an object?
Using the delete keyword followed by object.property (or object[‘property’])
What are the two ways to get or update the value of a property?
Dot notation or bracket notation.
What are arrays used for?
To store lists, usually ordered lists.