JavaScript Flashcards
What is the purpose of variables?
To use as an identifier in JavaScript and the variable must be identified with unique names.
How do you declare a variable?
Use var, let (variable with restricted scope), or const (a variable that can’t be reassigned) keyword.
How do you initialize (assign a value to) a variable?
Put = operator. var a = 1.
What characters are allowed in variable names?
The first character must start with a letter, underscore, or a dollar sign ($), and don’t forget variable names are case-sensitive and don’t use JavaScript’s reserved keywords.
What does it mean to say that variable names are “case sensitive”?
This means that any identifiers should always be typed with consistent character capitalization within acceptable rules.
What is the purpose of a string?
It is used for storing and manipulating text in JavaScript.
What is the purpose of a number?
It is a primitive wrapper object used to represent and manipulate numbers.
What is the purpose of a boolean?
It is used to represent one of two values in a value, such as True or False, Yes or No, and On or Off.
What does the = operator mean in JavaScript?
It performs some operation on single or multiple operands (data values) and produces a result.
How do you update the value of a variable?
Just update the new value under the same variable name or use temporary values.
What is the difference between null and undefined?
They are equal in value but different in type.
Why is it a good habit to include “labels” when you log values to the browser console?
To identify easier, faster, and more directly when you work on some big project or work with coworkers.
Give five examples of JavaScript primitives.
String, number, boolean, null, and undefined. Everything else is an object.
What data type is returned by an arithmetic operation?
It returns by numerical values.
What is string concatenation?
It is the process of appending one string to the end of another string.
What purpose(s) does the plus operator (+) serve in JavaScript?
It produces the sum of numeric operands or string concatenation.
What data type is returned by comparing two values (, ===, etc)?
It returns a boolean value.
What does the plus-equals (+=) operator do?
It adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
It is a standalone entity that holds multiple values in terms of properties and methods.
What are object properties?
It’s a variable that is attached to the object. It is sorted as the same as an ordinary variable except for the attachment to the object.
Describe object literal notation.
var object name = {property name: value of it, another property name: value of it}.
How do you remove a property from an object?
Use keyword delete the object name.property name or keyword delete object name[‘property name’].
What are the two ways to get or update the value of a property?
Object name.property name = value that you want to update or object name[‘property name’] = value that you want to update.
What are arrays used for?
It is used when you store a collection of variables of the same type.