JavaScript Flashcards
(169 cards)
• What is the purpose of variables?
o Variables create permanence in your data
o It creates a box and stores information
• How do you declare a variable?
o Use a keyword like let or var.
• How do you initialize (assign a value to) a variable?
o Use an assignment operator (SINGLE EQUAL SIGN “=”)
• What characters are allowed in variable names?
o _ underscore and $. BUT variable names CANNOT start with a numeric value.
• What does it mean to say that variable names are “case sensitive”?
o String and string are different.
o It is not good practice to use variable names that are the same but with different casing.
• What is the purpose of a string?
o JavaScript strings are for storing and manipulating TEXT.
o These character are written INSIDE quotes.
o The string object is used to represent and manipulate a sequence of characters
• What is the purpose of a number?
o To store numeric values FOR calculations – mathematical operations
• What is the purpose of a boolean?
o To express a value of True or false
o Kind of like a light switch –
o Necessary for conditions and comparisons
o Helpful to determine whether or not to execute or not. (ON/OFF | it IS or IS NOT)
o Purpose of Booleans is to make DECISIONS (Yes or No)
• What does the = operator mean in JavaScript?
o Assigner
• How do you update the value of a variable?
o Use the assignment operator and WOULD NOT USE the keyword.
o VAR keyword is only necessary when creating the variable for the first time.
o CONFUSING.
o Does this variable already exist in my code?
• What is the difference between null and undefined?
o Null is assigned
Null is a value that can only exist because someone has assigned it to something.
It is purposeful – since someone intentionally put it there
o Undefined
Undefined is organic.
If there is no return value, it will come back as undefined.
Undefined is assigned by the browser – the ONLY value that JS can use to say “nothing”
• Why is it a good habit to include “labels” when you log values to the browser console?
o For clarity so that when we return to the code, we can see what we were working on and not get confused.
o Labels makes it clear what we were working with.
• Give five examples of JavaScript primitives.
o String, number, Boolean, null, undefined.
• What data type is returned by an arithmetic operation?
o Numbers – not necessarily integers.
• What is string concatenation?
o Adding together multiple strings.
o Concatenation will NEVER change the original string.
o Strings are immutable.
o They can never, EVER change.
• What purpose(s) does the + plus operator serve in JavaScript?
o Summing numerical data or string concatenation.
• What data type is returned by comparing two values (<, >, ===, etc)?
o Boolean
• What does the += “plus-equals” operator do?
o Shorthand for reassigning a value of the original variable to the new value.
o =+ will make a lasting change to something while + will add but will not save the previous value.
• What are objects used for?
o Objects group together a set of variables and functions to create a model of something you would recognize from the real world.
o In an object, variables and functions take on new names.
• What are object properties?
o In an object, variables become known as properties.
o If a variable is part of an object, it is called a PROPERTY.
o Properties tell us about the object, such as the name of a hotel or the number of rooms it has.
o Each individual hotel might have a different name and a different number of rooms.
• Describe object literal notation.
o THEY ARE A SET OF CURLY BRACES
o Properties separated by a colon.
o Commas to separate lines.
• How do you remove a property from an object?
To delete a property, use the delete keyword followed by the object name and property name.
ex: delete hotel.name;
• What are the two ways to get or update the value of a property?
o Use a dot or the brackets
o Bracket notation might be used when a property is inside an existing object.
• What are arrays used for?
o Allows us to group data types (typically alike – but can be different) and gives us a way to put it into a list format and helps us deal with them one item at a time and see the scope of each item.