Week 2 Flashcards
What is the purpose of variables?
The purpose of a variable is to store data.
How do you declare a variable?
Use the keyword “var”.
How do you initialize (assign a value to) a variable?
Use the assignment operator “=” .
What characters are allowed in variable names?
We can use letters, $ dollar sign, _ underscore, and numbers but the word cannot start with a number.
What does it mean to say that a variable names are “case sensitive”?
It means that if the letter is capitalized or uncapitalized it makes a difference in calling a variable since it is two different variables. Score is not the same as score.
What is the purpose of a string?
Consists of letters and other characters. They are used to add new content into a page and the can contain HTML markup.
What is the purpose of a number?
Consists of numbers. Use for calculators, determining the size of the screen, moving the position of an element on a page, or setting the amount of time an element should take to fade in.
What is the purpose of a boolean?
Boolean is either true or false. Considered like a light switch. It is helpful when determining which part of a script should run.
What does the = operator mean in JavaScript?
Initialize a variable
How do you update the value of a variable?
Using the assignment operator.
What is the difference between null and undefined?
Null: It is the intentional absence of the value. It is one of the primitive values of JavaScript. Undefined: It means the value does not exist since there are no arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
It can be confusing without since we do not know what the console.log is printing if there is a lot. It would be easier to identify what is being consoled.
Give 5 examples of JavaScript primitives.
String, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
When connecting two strings together.
What purpose(s) does the + plus operator serve in JavaScript?
Used for addition. Adds one value to another.
What data type is returned by comparing two values (<, >, ===, etc.)
Boolean
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.
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.
What are object properties?
Variables become properties.
Describe object literal notation.
The object is the curly braces and their contents. The object is stored in a variable and would be referred to the name of the object when being called. Then inside the curly braces, you have properties. The properties are separated from the value using colon and you also separate each property or method using commas. Last, add a semicolon to the closing curly brace.
How do you remove a property from an object?
Using delete operator.
Ex: delete object.property
What are two ways to get or update the value of a property?
Using dot or bracket notation.
What are arrays used for?
Consider using arrays whenever you are working with a list or a set of values that are related to each other.
Describe array literal notation.
Declare the array as a variable and then use square brackets and have your list inside of the square bracket and using commas to separate each content of the list.
How are arrays different from “plain” objects?
Arrays are a special type of object. They hold a related set of key/value pairs, but the key for each values is its index number.
What number represents the first index of an array?
0
What is the length property of an array?
To tell us the total count of the array.