JavaScript Flashcards
What is the purpose of variables?
To give us a location to store data and information to do something with it and use it again in the future.
How do you declare a variable?
Use the var keyword and then followed by the name of the variable. example:
var totalPets =
How do you initialize (assign a value to) a variable?
Using the assignment operator ( = )
What characters are allowed in variable names?
Letters, numbers, $ and underscore.
numbers are allowed as long as it is not the first character in the value. So “cat1” works but not “1cat.”
What does it mean to say that variable names are “case sensitive”?
Being “case sensitive” means that keywords should be exact.
What is the purpose of a string?
To represent text rather than numbers.
What is the purpose of numbers?
To count, measure, and calculate.
(example: you would store it as a string because you don’t do ‘math’ with your zip code. A zip code is an identifier. Other examples include address, telephone number, and SSN)
What is the purpose of a boolean?
To define whether an expression is true or false.
Booleans’ purpose is for computers for making a choice. This gives comp only two choices: “true” or “false.”
What does the = operator mean in JS?
A symbol used to perform operations on operands (values and variables).
How do you update the value of a variable?
State var name, assignment operator and then the new value.
What is the difference between null and undefined?
null is the intentional absence of a value so then you can go back and store a value. It indicates that it does exist but it is not assigned anything.
Undefined means it is also empty but the computer will assign it as it not having any value.
Why is it a good habit to include “labels” when you log values to the a browser console?
labels describe what you are inputting. It is mainly for organization.
Give 5 examples of JS primitives.
JS primitive types are data that is not an object and has no methods or properties.
1) string
2) booleans
3) numbers (also bigint- which are for really big numbers)
4)null
5) undefined
What data type is returned by an arithmetic operation?
Number data type
What type of data type is NaN?
NaN = not a number BUT
NaN is a number data type.
What is string concatenation?
Combines more than one string together. It’s like a secondary functionality for the + operator other than for math.
What purpose(s) does the + plus operator serve in JavaScript?
It can concatenate string and serves as an addition command, adding numbers together.
What data type is returned by comparing two values (, ===, etc)?
Boolean values.
What does the += “plus-equals” operator do?
Takes right operand value and adds it to current value (left operand) and then becomes the new value of the left operand.
What are objects used for?
Group together a set of properties to store data.
What is the reason to group data together to make objects?
Objects are a collection of variables to put them in a category indicating that they are similar.
What are object properties?
Individual pieces of data assigned as a variable that is associated with an object.
Describe Object Literal Notation.
It starts with a variable and it is defined by an array of key:value pairs separated by colons and then a comma after every key:value pairs except for the last pair of the array.
example:
var student = {
firstName: ‘Sharon’,
lastName: ‘Tieu’
};
How do you remove a property from an object?
use the Delete operator or use dot notation or bracket notation.