JavaScript Flashcards
What is the purpose of variables?
To store data(information) for a script.
How do you declare a variable?
You must declare the variable with a name. Providing a keyword (var) to declare a variable with a name.
How do you initialize (assign a value to) a variable?
You use the equal sign = (assignment)
What characters are allowed in variable names?
Letters, numbers (if it’s not the first character), $ or _
What does it mean to say that variable names are “case sensitive”?
Lowercase and uppercase letters are different.
What is the purpose of a string?
To hold a sequence of characters or text.
What is the purpose of a number?
For math and calculations.
What is the purpose of a boolean?
Conditional data type to determine if something is true or false.
What does the = operator mean in JavaScript?
It assigns things.
How do you update the value of a variable?
Use the variable name and assign it a new value.
What is the difference between null and undefined?
null is an intentional absence of value. Must be assigned.
undefined – javaScript says there’s nothing there.
Why is it a good habit to include “labels” when you log values to the browser console?
There’s no context as to what it is or where it came from without labels.
Give five examples of JavaScript primitives.
String, number, Boolean, null, undefined.
What data type is returned by an arithmetic operation?
numbers
What is string concatenation?
Combines multiple strings together.
What purpose(s) does the + plus operator serve in JavaScript?
Addition adds one value to another.
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Adds the value to the right of the operand to a variable and assigns the result to the variable.
What are objects used for?
Group together a set of variables or properties and values to describe something. A collection of variables.
What are object properties?
Properties or variables that have a value within an object.
Describe object literal notation.
Assign an object literal to a variable. Within the object are names of properties and their corresponding values.
How do you remove a property from an object?
Delete operator Ex. delete pet.name
What are the two ways to get or update the value of a property?
Dot notation or bracket notation.
What are arrays used for?
Arrays store a list of values. Values can then be accessed if they are in a numbered list.
Describe array literal notation.
Create an array and give it a name. the values are assigned to the array inside a pair of brackets and each value is separated by a comma.
How are arrays different from “plain” objects?
Arrays have a length property. Arrays have an order. Objects you create properties and assign them a value. Arrays you would normally assign a method to add data to an array. arr.push() can also arr[0] = “Something”
What number represents the first index of an array?
0
What is the length property of an array?
It tells you how many items are in an array. .length
How do you calculate the last index of an array?
Length property -1. .length - 1
What is a function in JavaScript
It’s a tool used to write code for reuse throughout a program, giving a name to a handful of code statements to make it easier to read and makes code dynamic to handle many situations. It takes in data and spits out data.
Describe the parts of a function definition.
Function keyword to begin the creation of a function.
An optional name of the function.
A list of zero or more parameters within parentheses.
The start of the functions code block indicated by an opening curly brace {
An optional return statement.
End of the function code block indicated by closing curl braces }
Describe the parts of a function call.
The functions name.
List of zero or more arguments within parentheses.
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition has a code block and a keyword.
What is the difference between a parameter and an argument?
We declare or define parameters during the definition of the function. It is a placeholder variable whose value is not known until we call the function and pas san argument. An argument is the actual value that will be passed through to the parameter.
Why are function parameters useful?
Parameters are placeholders for variables. When we call a function we can pass whatever arguments we want to the parameter. We can change the output by calling the function with the arguments and the parameters will change within the codeblock to whatever we set the argument to. Parameters allow a function to perform tasks without knowing the specific input values ahead of time.
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.
Prevents any more code in the function’s code block from being run.
Give 6 examples of comparison operators.
> < >= <= === !==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
Evaluates or checks a condition. If the condition is true, the statements in the following codeblock are executed. To make a choice.
Is else required in order to use an if statement?
No. If you require code to run only when the statement returns true an else statement is not needed.
Is else required in order to use an if statement?
No. If you require code to run only when the statement returns true an else statement is not needed.
Describe the syntax (structure) of an if statement.
Keyword if
Condition (score>=50)
Opening a curly brace for declaration block
the code to execute.
Closing curly brace for the declaration block.
What are the three logical operators?
&& (logical and), || (logical or), ! (logical not)