JavaScript Flashcards
(117 cards)
What is the purpose of variables?
A variable is a way to store values
How do you declare a variable?
To declare (create) a variable, you will specify the type, leave at least one space, then the name for the variable and end the line with a semicolon. var x; this variable has been declared but the value is undefined
How do you initialize (assign a value to) a variable?
with = assignment operator
What characters are allowed in variable names?
The period, the underscore, and the characters $, #, and @ can be used within variable names. For example, A. _$@#1 is a valid variable name.
What is the purpose of a string?
To store text data
What is the purpose of a number?
What is the purpose of a boolean?
Boolean data types can have one of two values: true or false, used to create true/false statements.
(Booleans are helpful when determining which part of a script should run.)
What is the difference between null and undefined?
null is an assigned value. It means nothing. undefined means a variable has been declared but not defined yet.
How do you update the value of a variable?
Give five examples of JavaScript primitives.
In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods or properties.
There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null.
Why is it a good habit to include “labels” when you log values to the browser console?
A console log “label” is simply a short string that describes the variable or value being logged.
Since the console.log() method can write multiple values to the console at the same time, it’s easy to include a “label” when printing a value.
How do you update the value of a variable?
Once you have assigned a value to a variable, you can then change what is stored in the variable later in the same script.
Once the variable has been created, you do not need to use the var keyword to assign it a new value.
var inStock;
var shipping;
inStock = true;
shipping = false;
inStock = false;
shipping =true;
What data type is returned by an arithmetic operation?
Number data type
What is string concatenation?
Combination of two or more strings
What purpose(s) does the + plus operator serve in JavaScript?
Addition operator. Arithmetic operation with numbers and combinations for stings
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean (true or false)
What does the += “plus-equals” operator do?
Adds new variable to the current variable. Changes/reassigned the value
Unary operators
A unary operation is an operation with only one operand.
(delete
The delete operator deletes a property from an object.)
typeof
The typeof operator determines the type of a given object.
+
The unary plus operator converts its operand to Number type.
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.
What are object properties?
A property of an object can be explained as a variable that is attached to the object. Object properties are basically the same as ordinary JavaScript variables, except for the attachment to objects.
The properties of an object define the characteristics of the object. You access the properties of an object with a simple dot-notation:
Describe object literal notation.
The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array.
What are arrays used for?
An array is a special type of variable. It doesn’t just store one value; it stores a list of values.
Describe array literal notation
The values are assigned to the array inside a pair of square brackets, and each value is separated by a comma. The values in the array do not need to be the same data type, so you can store a string, a number, and a Boolean all in the same array.
colors = [‘white’, ‘black’, ‘custom’];
Describe the parts of a function definition.
The function keyword to begin the creation of a new function.
An optional name. (Our function’s name is sayHello.)
A comma-separated list of zero or more parameters, surrounded by () parentheses. (Our sayHello function doesn’t have any parameters.)
The start of the function’s code block, as indicated by an { opening curly brace.
An optional return statement. (Our sayHello function doesn’t have a return statement.)
The end of the function’s code block, as indicated by a } closing curly brace.