prep-javascript-variables, objects, and arrays Flashcards
What does the = (equals) operator do in JavaScript?
The = (equals) operator in JavaScript is an assignment operator. It assigns the value of the variable(s) on the right side of the = (equals) operator to the variable on the left side of the = (equals) operator.
Which keyword is used to declare a variable in JavaScript?
var, let, or const
Which characters is a JavaScript variable allowed to begin with?
A letter, $, or _
What are quotation marks used for in JavaScript?
To create string values
What is the purpose of strings in JavaScript?
To hold text values like “John Doe” in a variable,
and
JavaScript strings are for storing and manipulating text.
What is the purpose of booleans in JavaScript?
JavaScript booleans are often used to find out if an expression or variable is true or not
Ex: “Boolean(10 > 9)” would return the boolean value of “true”.
What is the purpose of numbers in JavaScript?
The purpose of numbers in JavaScript is to store numeric values (decimal and non-decimal) in variables.
Arithmetic operations can be performed on these variables that hold numeric values such as addition, subtraction, division, modulo, etc.
What does null mean in JavaScript?
“null” means an object has no value.
An object can be assigned “null” to show that it has no value.
This is different from “undefined” because “undefined” means that a value has not been set for a variable when the variable was declared.
What data types can object properties hold?
strings, numbers, arrays, booleans, functions
Describe the syntax (structure) of object-literals in JavaScript.
Ex: const person = {firstName: “John”, lastName: “Doe”, age: 50, eyeColor: “blue”};
The syntax of object-literals consists of the use of the keyword “const” followed by the variable name; and it is assigned the properties and property values to the right of the equal (=) sign operator, which are separated by commas inside curly braces.
What is the principal use of arrays?
To store “list” type data in a numerically indexed data structure, which is zero-indexed.
Describe the syntax (structure) of array-literals in JavaScript.
const array_name = [item 1, item 2, …];
What number represents the first index of an array?
0
How can you access the last element of an array?
lastElement = myArray[myArray.length - 1];