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.
Describe array literal notation.
var array object name = [‘’, ‘’, ‘’ ];
How are arrays different from “plain” objects?
Objects represent a special data type that is mutable and can be used to store a collection of data. On the other hand, arrays are a special type of variable that is also mutable and can also be used to store a list of values.
What number represents the first index of an array?
0.
What is the length property of an array?
The length property sets or returns the number of elements in that array.
How do you calculate the last index of an array?
the length of the array - 1.
What is a function in JavaScript?
It is a code to perform a particular task or calculate a value.
Describe the parts of a function definition.
keyword function, name of the function, parameter, but it should take some input and return output and there is some obvious relationship between them
Describe the parts of a function call.
Keyword function and give the name of the function and put parenthesis (give parameter or not). You should define the function in the scope from which you wish to call it.
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition’s meaning is to remember the method of it but stays still. On the other hand, a function call instructs JavaScript to execute the code of the function.
What is the difference between a parameter and an argument?
The parameters are listed inside of the parenthesis. The arguments are the values received by the function when it is invoked.
Why are function parameters useful?
Because those are expected to be the same as variables except that the values of these variables are defined when we call the function.
What two effects does a return statement have on the behavior of a function?
It ends the execution of a function and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.
Why do we log things to the console?
It prints the output to the console, so we can see what is going on, and be able to fix the code if something is wrong.
What is a method?
It is a function that is a property of an object.
How is a method different from any other function?
A method is a function that belongs to an object.
How do you remove the last element from an array?
Use array pop() method. name of array.pop();
How do you round a number down to the nearest integer?
Use Math.floor() function.
How do you generate a random number?
Use Math.random() function.