JavaScript Flashcards
What is the purpose of variables?
To store data
How do you declare a variable?
Var variablename= variable value
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
Letter, $, or _, numbers after first character
What does it mean to say that variable names are “case sensitive”?
Variable name can be different for capital or lowercase same name
What is the purpose of a string?
Store text a sequence of characters
What is the purpose of a number?
Store a number, calculations
What is the purpose of a boolean?
Store true or false values, render a sate of something is or isn’t
What does the = operator mean in JavaScript?
Assignment operator, assigning a value to the variable.
How do you update the value of a variable?
Variablename = newvalue
What is the difference between null and undefined?
Null: value can only be assigned, not generated, developer set variable = null purposely. placeholder empty for now
Undefined: empty, nothing here
Why is it a good habit to include “labels” when you log values to the browser console?
To understand which console log is being output
Give five examples of JavaScript primitives.
Number, String, Boolean, Undefined, Null and Symbol
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Joining together 2 or more strings, result will be a string
What purpose(s) does the + plus operator serve in JavaScript?
cocatenate or add
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
The addition assignment (+=) operator adds the value of the right operand to a variable and assigns the result to the variable
What are objects used for?
Grouping together related variables
What are object properties?
Piece of data stored in the object, collection of variables
The key and value in the objects
Describe object literal notation.
Var object = {
Key: value,
Key: value
};
How do you remove a property from an object?
Delete object.property
What are the two ways to get or update the value of a property?
Dot notation object.property
Bracket notation object[property]
What are arrays used for?
Lists of data where either order is important or not important
Describe array literal notation.
Var arrayname;
Arrayname = [‘value1’, ‘value2’];
bracket separated by commas
How are arrays different from “plain” objects?
has a length property and keeps updating
call a method to add data to the array
What number represents the first index of an array?
0
What is the length property of an array?
Number of items in the array
How do you calculate the last index of an array?
Array.length -1
What is a function in JavaScript?
Performs a task and returns the output
Describe the parts of a function definition.
Function(called keyword) functname (parameters) { Code block;
Return ;
}
Describe the parts of a function call.
functionname(argument1, argument2, etc);
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call is running the code
Function definition is creating the object, has a codeblock { } and function keyword
What is the difference between a parameter and an argument?
Parameter is a placeholder for a variable we don’t know until we call the function and pass an argument
When defining a function, we declare parameters.
When we call a function we pass it an argument
Why are function parameters useful?
So we can write the function once and insert any argument we want when we run the function
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value we can use in our program (get the output to wherever the function was called)
Prevents any more code in the function’s code block from being run (stops function from running)
Give 6 examples of comparison operators.
> , <, >=, <=, ===, and !==
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
To guide the computer to make a decision based on criteria
Is else required in order to use an if statement?
No If you require code to run only when the statement returns true
Describe the syntax (structure) of an if statement.
If (condition) {
code block -Return value;
} else { code;
}
What are the three logical operators?
&& || !
How do you compare two different expressions in the same condition?
Using a && or ||
Why do we log things to the console?
To find errors and warnings as they occur in the JavaScript code.
Debugging, something is broken, understand what’s happening
What is a method?
a function which is a property of an object. Using an object then a . then method name, performs a function
How is a method different from any other function?
method is associated with an object, while a function is not.
method: object.method
function: state it
How do you remove the last element from an array?
arrayname.pop();, arrayname.shift() removes first element
How do you round a number down to the nearest integer?
Math.floor(numberhere);
How do you generate a random number?
Math.random() -random float value from 0 to 1 (is a percentage)
How do you delete an element from an array?
arrayname.splice();
splice method at the index array
How do you append an element to an array?
arrayname.push() adds to end/ arrayname.unshift() adds to beginning