JavaScript Flashcards
What is the purpose of variables?
The purpose of variables is to store value.
Why does this help? Variables can change & it exists for a longer time.(data permanence)
How do you declare a variable?
You declare a variable by using the var keyword and giving the variable a name.
How do you initialize (assign a value to) a variable?
You initialize (assign a value to) a variable with the = operator.
What characters are allowed in variable names?
Letters, numbers, dollar sign($), and underscore(_).
Note: dash(-) or period( . ) or question-mark(?) are not allowed & Numbers cannot go first.
What does it mean to say that variable names are “case sensitive”?
When it is said that variable names are “case sensitive” it means that capitalization matters.
Ex: String and string are not the same.
What is the purpose of a string?
The purpose of a string is to store text.
What is the purpose of a number?
The purpose of a number is to use it for math and calculations.
What is the purpose of a boolean?
The purpose of a boolean is to store if something is true or false. Booleans exist for decision making.
What does the = operator mean in JavaScript?
The = operator in JavaScript means that we are assigning a value to something.
How do you update the value of a variable?
You update the value of a variable by assigning a new value to the variable.
Note: You don’t need the var keyword to assign a new value to an existing variable.
What is the difference between null and undefined?
Null: Primitive value that represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. Null always need to be assigned to something.
Undefined: Primitive value automatically assigned to variables that have only been declared. Also assigned to formal arguments where there are no actual arguments.
What data-type is returned by an arithmetic operation?
A Number value is returned by an arithmetic operation.
What is string concatenation?
String concatenation is adding two or more strings to make a longer string.
What purpose(s) does the + plus operator serve in JavaScript?
The + plus operator adds numbers and concatenates strings in JavaScript.
What data type is returned by comparing two values (< , >, ===, etc)?
A Boolean value is returned by comparing two values (< , >, ===, etc).
What does the += “plus-equals” operator do?
A value on the right-side will be added to the variable, and the variable will then be updated to that new value.
What are objects used for?
Objects are used to group together a set of properties and methods to create a model of something.
What are object properties?
Object properties are variables glued to that object.
Describe object literal notation.
var hotel = { name: 'Cosmopolitan', rooms: 500, booked: 300, checkAvailability: function( ) { return this.rooms - this.booked; } };
How do you remove a property from an object?
Removing a property from an object using the dot notation:
delete objectname.propertyname.
Removing a property from an object using the bracket notation:
delete objectname[‘propertyname’].
What are the two ways to get or update the value of a property?
Updating/getting a property from an object using the dot notation: variablename.propertyname.
Updating/getting a property from an object using the bracket notation: variablename[‘propertyname’].
What are arrays used for?
Arrays are used to store a list of data with number indexes.
Describe array literal notation.
colors = [‘white’, ‘blue’, ‘red’]
How are arrays different from “plain” objects?
Arrays have orders to them unlike “plain” objects. Arrays will repair itself if a data is deleted.