Javascript Flashcards
What is the purpose of variables?
To store data
How do you declare a variable?
Keyword var/let/const + name of variable
How do you initialize (assign a value to) a variable?
Using the assignment operator. (=)
What characters are allowed in variable names?
letters , numbers, $ dollar sign, _ underscore
What does it mean to say that variable names are “case sensitive”?
A variable starting with a lowercase and a variable starting with an uppercase will create two separate variables.
What is the purpose of a string?
Hold data type consisting of letters/ other characters. Any type of text content.
What is the purpose of a number?
Hold any data type handling numbers/numeric values. Counting, calculating sums, determining size, moving the position, setting time, etc.
What is the purpose of a boolean?
To hold data types of true or false.
What does the = operator mean in JavaScript?
Assign a value to the variable, also used to update the value given to a variable.
How do you update the value of a variable?
- Using the assignment operator.
- Do not need to use ‘var’ again, just the name and (=)
What is the difference between null and undefined?
- Null represents a placeholder value, might hold value in the future.
- Undefined is a value that has not been thought of yet, does not hold value yet.
Why is it a good habit to include “labels” when you log values to the browser console?
To help debug. It makes it clearer which variables are being logged and in which order.
Give five examples of JavaScript primitives.
String, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
A numerical value
What is string concatenation?
The joining of two or more strings using (+) to create a new string
What is string concatenation?
The joining of two or more strings using (+) to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
- This will combine the value of the string before and after the (+) operator (a concatenated string)
- Addition for numerical numbers.
What data type is returned by comparing two values (<, >, ===, etc)?
True/False
What does the += “plus-equals” operator do?
This will add the number value on the right and assigns the result to the variable
What are objects used for?
To group together a set of variables and functions to create a model.
What are object properties?
Variables that are part of an object.
Describe object literal notation.
The object is in curly braces with its contents, then stored in a variable. Each key is separated from its value using a colon and each property and method is separated with a comma.
Var (varName) = { property: ‘string’, };
How do you remove a property from an object?
- Use keyword delete then dot notation to identify the property or method you want to remove from the object.
- Delete var.varName;
What are the two ways to get or update the value of a property?
Using square brackets or dot notation.
Bracket:
varName[‘newString’] = ‘updatedVal’;
Dot: varName.newString = updatedVal;
What are arrays used for?
To create ordered list of data.
Describe array literal notation.
Var varName = [ ‘one’, ‘two’, ‘three’];
- Open brackets
- List of data values followed by commas
How are arrays different from “plain” objects?
- Arrays are a special type of objects, they hold a related set of values
- Arrays use numbers as indexes
What number represents the first index of an array?
0
What is the length property of an array?
Gives you the total number of items in an array
How do you calculate the last index of an array?
- Subtracting 1 from the array length
- arrayName.length - 1
What is a function in JavaScript?
- An object that can be called to make code more dynamic.
- A set of statements to perform a task or calculate a value.
Describe the parts of a function definition.
- Function keyword to begin the creation of a new function
- An optional name for the function
- Zero or more parameters surrounded by parentheses.
- { } opening and closing curly brace for the start and end of the function code block.
- Optional return statement.
Describe the parts of a function call.
Function name, 0 or more arguments surrounded by parentheses.
When comparing them side-by-side, what are the differences between a function call and a function definition?
- The definition has a series of statements to be run in the codeblock.
- The function call is just the function name.
What is the difference between a parameter and an argument?
- Parameter: a placeholder / stores local variables to the function
- Argument: the value that we want to use for the function.
Why are function parameters useful?
Parameters are useful because they can be replaced with different arguments to run the same code block on that argument.
What two effects does a return statement have on the behavior of a function?
- Produces a value from the function.
- Prevents any more code in the function’s code block from being run.
- A return will exit the function, any code after a return will not be logged..