JavaScript Flashcards
(124 cards)
What is the purpose of variables?
the ability to store data that can change every time a script runs.
How do you declare a variable?
var (keyword) varName(Variable Name/Identifier) = (Assignment Operator) number/string/boolean(Value)
How do you initialize (assign a value to) a variable?
use an equals sign(=) . aka the Assignment Operator
What characters are allowed in variable names?
letters, numbers, dollar sign($), underscore(_),
cannot start with a number.
no dash(-) or period(.) in a variable name.
no keywords or reserved words.
What does it mean to say that variable names are “case sensitive”?
an example would be that var alvaro and var Alvaro would be different variable names.
try not to create variables that have the same name doing different things.
What is the purpose of a string?
strings can be used when working with some type of text.
What is the purpose of a number?
when working with any arithmetic or something with a numeric value
What is the purpose of a boolean?
to tell whether true or false, also to tell JS which path to take.
What does the = operator mean in JavaScript?
Assignment Operator
How do you update the value of a variable?
you can use dot notation or square brackets.
What is the difference between null and undefined?
null is something you place there and undefined is placed there by the browser.
Why is it a good habit to include “labels” when you log values to the browser console?
to help clarify whats being logged when you go back and review the code.
Give five examples of JavaScript primitives.
Numeric value, String, Boolean value, null, and undefined.
What data type is returned by an arithmetic operation?
always a numeric value.
What is string concatenation?
connecting two different strings or data that you want to be together.
What purpose(s) does the + plus operator serve in JavaScript?
its the addition operator, as well the concatenation operator.
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean value (true or false).
What does the += “plus-equals” operator do?
the addition assignment operator adds the value of the right side(right operand) and assigns the result to the variable.
What are arrays used for?
to store a list of related values.
Describe array literal notation.
var example = [‘one’, ‘two’, ‘three’];
How are arrays different from “plain” objects?
arrays are indexed such as 0, 1, 2, 3
objects cant use .length property.
What number represents the first index of an array?
0
What is the length property of an array?
length property tells you how many items are in the array.
How do you calculate the last index of an array?
var lastIndex = arrayName.length;
use dot notation = .length