JavaScript Flashcards
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of variables?
Variables are used to store data for the computers to use in the future
For the future;
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
How do you declare a variable?
use a keyword (var, let, const) and variable name and =
Example: var example = 100;
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
How do you initialize (assign a value to) a variable?
use an equal sign
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What characters are allowed in variable names?
letter, numbers, $, underscore,
numbers cant be first
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What does it mean to say that variable names are “case sensitive”?
Car= and car= are different variables
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of a string?
for storing text that wouldn’t make sense to JavaScript
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of a number?
For doing calculations;
If the number is a zipcode then store as string;
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of a boolean?
it is for letting computers make a decision that is true or false;
to make decisions
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What does the = operator mean in JavaScript?
assignment operator
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
How do you update the value of a variable?
Update the value of a variable by assigning a new value to the variable name without the keyword
Example: let a = 2; for declaring a variable a = 5; for updating a variable (no need for keyword)
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the difference between null and undefined?
- null is absents of value intentionally
(ex: optional user input) - undefined is not trustworthy
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
Why is it a good habit to include “labels” when you log values to the browser console?
Label within the console.log to know where you’re getting values from / for organization purposes
(especially when going back to the code)
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
Give five examples of JavaScript primitives.
string, number, boolean, null, and undefined
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What data type is returned by an arithmetic operation?
numeric data
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What is string concatenation?
Process of joining together two or more strings to create one new string
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS What purpose(s) does the + plus operator serve in JavaScript?
adds one value to another;
addition of numbers and concatenation of strings
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What data type is returned by comparing two values
(>, ===, < etc)?
booleans (true or false)
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What does the += “plus-equals” operator do?
left operand = left operand + right operand
Example: 2 += 3 = 5
JAVASCRIPT-OBJECTS
What are objects used for?
objects {} are used group together a set of variables and functions to create a model / representation of something
JAVASCRIPT-OBJECTS
What are object properties?
properties tell us about the object;
the variable of an object;
Example: name, age, etc.
JAVASCRIPT-OBJECTS
Describe object literal notation.
Store object in variable, within opening and closing curly braces are properties and their values;
Example: var object = { properties: value }
JAVASCRIPT-OBJECTS
How do you remove a property from an object?
Use delete operator
Example:
delete object.property or delete object[‘property’]
JAVASCRIPT-OBJECTS
What are the two ways to get or update the value of a property?
dot notation or bracket notation
JAVASCRIPT-ARRAYS
What are arrays used for?
Array are used for storing values in a grouped list like a grocery list where orders are not essential;