JS Flashcards
What is the purpose of variables?
to store and remember information
How do you declare a variable?
the js keyword var var fullName = 'aly'
How do you initialize (assign a value to) a variable?
= assignment operator
What characters are allowed in variable names?
letters, $ and _
What does it mean to say that variable names are “case sensitive”?
captialization and lower case letters are different from each other
What is the purpose of a string?
to hold sentences and strings and a string of characters
What is the purpose of a number?
to hold the value of a number, and for using math in js
What is the purpose of a boolean?
T/F, its how js makes decisions in code
What does the = operator mean in JavaScript?
assignment operator, assigns a value to a variable
How do you update the value of a variable?
you change the value and whats on the right side of the assignment operator
What is the difference between null and undefined?
null represents and points to a nonexsitent or invalid object, a human purposely assigned its value to null.
undefined automatically assigned to variables that have just been declared. Never been assigned by a human that is js machine telling you something is undefined.
Why is it a good habit to include “labels” when you log values to the browser console?
a way of debugging and organization so you know what value goes to what variable
Give five examples of JavaScript primitives.
null, undefined, string, boolean, number
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Concatenate is a fancy programming word that means “join together”. Joining together strings in JavaScript uses the plus (+)
let one = 'Hello, '; let two = 'how are you?'; let joined = one + two; joined;
What purpose(s) does the + plus operator serve in JavaScript?
adds one value to another
What data type is returned by comparing two values (, ===, etc)?
a boolean T/F
What does the += “plus-equals” operator do?
The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator.
let a = 2; let b = 'hello';
console.log(a += 3); // addition // expected output: 5
console.log(b += ' world'); // concatenation // expected output: "hello world"
What are objects used for?
Objects group together a set of variables and functions to create a model
of a something you would recognize from the real world. In an object,
variables and functions take on new names.
key:value pair
What are object properties?
variables that hold information about the object, key:value
Describe object literal notation
how to access an object’s properties, or add/delete key value points.
pet.name = ‘scout’
How do you remove a property from an object?
using the delete keyword and bracket/dot notation
delete pet.name;
delete pet[‘name’];
What are the two ways to get or update the value of a property?
dot notation
pet.name
brackets - use if property name is a number or a variable is being used in place of the property name
What are arrays used for?
to list together a group of related data