JavaScript Flashcards
What is the purpose of variables?
Variables are used to store bits of data.
With a variable, we can assign a values to names, which will then be stored as a variable, and which we can return to later.
How do youdeclarea variable?
Using a variable keyword and a variable name…
var quantity;
How do you initialize (assign a value to) a variable?
Using an assignment operator and a variable value…
quantity = 3;
What characters are allowed in variable names?
The name must begin with a letter, dollar sign, or an underscore. It must not start with a number.
The name can contain letters, numbers, dollar sign, or an underscore.
(Note that you must not use a dash or a period in a variable name. You also cannot use keywords or reserved words.)
What does it mean to say that variable names are “case sensitive”?
It means that a variable with a capital letter and a variable with a lowercase letter would be two separate variables….
“score” and “Score” would be two different variable names. Javascript is sensitive to upper and lower casings.
What is the purpose of a string?
Strings are useful for storing characters/text data.
‘this is a string’
The strings data type consists of letters and other characters. This content is enclosed with double or single quotes. Strings can be used when working with any kind of text. They are frequently used to add new content into a page and they contain HTML markup.
Any character can be inside a string, including emojis
What is the purpose of a number?
Numbers are useful for storing numeric value to do calculations, mathematical operations, or really anything having to do with numbers.
The numeric data type handles numbers. Numbers are not only used for things like calculators; they are also used for tasks such as 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?
Booleans are useful for making decisions, like true or false, yes or no.
Boolean data types can have two values: true or false.
You can think of it a little like a light switch - it is either on or off. Booleans are helpful when determining which part of a script should run.
What does the=operator mean in JavaScript?
The = operator is an assignment operator and is used to assign values to variables.
How do you update the value of a variable?
You can state the variable name and assign it a new value. The old value will be replaced with the new value.
What is the difference betweennullandundefined?
Both mean ‘empty’, however, null is a developer’s way of saying ‘empty’, meanwhile undefined is javascript’s way of saying ‘empty’.
Null is a purposeful value. It is an intentionally assigned value of ‘nothing’ that must be put there on purpose. It’s typically used as a placeholder where value will be assigned later on.
Undefined appears organically from the javascript language and means that something has been declared but has not been defined (like declaring an empty variable).
Why is it a good habit to include “labels” when you log values to the browser console?
It is helpful to include labels when logging values that way you know exactly which value belongs to exactly which variable.
It also becomes extremely helpful in debugging and overall is a good habit so that the code stays clean and easy to understand.
Give five examples of JavaScript primitives.
Strings ('I am a string') Numbers (24) Booleans (true) (false) Undefined (undefined) Null (null)
What data type is returned by an arithmetic operation?
Numbers!
What is string concatenation?
String concatenation is when you combine two strings together using the addition assignment to create a new string.
What purpose(s) does the+plus operator serve in JavaScript?
The addition operator (+) can be used in numerical calculations but can also be used to concatenate strings together.
What data type is returned by comparing two values (,===, etc)?
A boolean value. (true/false)
What does the+=”plus-equals” operator do?
(Addition assignment operator) It adds the value of the righthand operand with the value of the lefthand variable, and reassigns the result of the expression to the variable. x += y ...is equal to... x = x + y
What are objects used for?
Objects are use to group together related variables.
What are object properties?
Object properties are variables within an object.
Object properties consist of keys and names which are stored as variables within an object. Technically, properties are variables, but they are properties when they live inside of an object.
Describe object literal notation.
Objects in literal notion consist of curly brackets in which there are properties. The properties consist of keys and values. Keys are separated from the values with a colon, and each property is separated with a comma. (The last property does not need a comma afterwards.)
Var object = { car: ‘audi’, color: ‘vibrant blue’, convertible: true, price: 70000 };
How do you remove a property from an object?
Using the delete operand in either dot or bracket notation…
delete object.color;
deleted object[‘color’];
What are the two ways to get or update the value of a property?
Using dot notation or bracket notation.
dot notation:
object. color;
object. color = ‘red’;
bracket notation:
object[‘color’];
object[‘color’] = red;
What are arrays used for?
Arrays are a way to store data in a numbered list. Each array item is assigned to an index number.
Arrays are useful for lists or groups of similar data not needing their own label.
Describe array literal notation.
Array literal notation consists of values stored within square brackets, and separated by commas. Arrays can store multiple types of data and each value is assigned to an index number.
var array = [ 'item one', 'item two', 'item three', ];
How are arrays different from “plain” objects?
Arrays are a special kind of object, where instead of values being assigned to key names, the values are instead assigned to an index in numerical order.
Arrays bring different benefits as opposed to plain objects because of this. Like how you can access values by their index number, or check to see the total number of values stored within the array. It is also useful when storing data in which you don’t know how much room you’ll need, since you can continue to add or delete values from an array without first declaring a spot for them.