JavaScript Flashcards
What is the purpose of variables?
Variables can hold any data value and can changed anytime
How do you declare a variable?
You declare using var (keyword) and variable name
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
Letter, dollar sign, and underscore to start and numbers
What does it mean to say that variable names are “case sensitive”?
First letter shouldn’t be capitalize and every letter capitalized after is different string value than the non-capitalized string values.
What is the purpose of a string?
To hold values as letters/text and change
What is the purpose of a number?
To hold values as numbers for arithmetic
What is the purpose of a boolean?
To hold values of true or false for decision making
What does the = operator mean in JavaScript?
Putting a value into something
How do you update the value of a variable?
Assign a new value
What is the difference between null and undefined?
They both represent empty value but null is empty on purpose - it has to be assigned to something while undefined is not assigned a value.
Why is it a good habit to include “labels” when you log values to the browser console?
Gives us point of reference
Give five examples of JavaScript primitives
String, boolean, number, null, undefined, symbol
What data type is returned by an arithmetic operation?
numeric data type
What is string concatenation?
Process of joining together two or more strings
What purpose(s) does the + plus operator serve in JavaScript?
Addition and string concatenation
What data type is returned by comparing two values (, ===, etc)?
Boolean data type
What does the += “plus-equals” operator do?
adds the value of the additional data value to a variable and assigns the result to the variable
What are objects used for?
Object groups a set of variables(properties) and functions(methods) to create a model.
What are object properties?
Variables that are part of the object
Describe object literal notation.
{} with whatever properties : method name
How do you remove a property from an object?
with the delete operator
What are the two ways to get or update the value of a property?
Dot or bracket notations
What are arrays used for?
Array is used to store list of values and indexed with set order
Describe array literal notation.
Array literal notation is using [] to list with data separated by commas
How are arrays different from “plain” objects?
Arrays are list with set order
What number represents the first index of an array?
[0]
What is the length property of an array?
It shows the total number of items in the array
How do you calculate the last index of an array?
[length - 1]
What is a function in JavaScript?
Set of statement grouped to perform a specific task and be repeatable
Describe the parts of a function definition.
Function keyword is used to create a new function followed by optional name and () then {} and optional return statement
Describe the parts of a function call.
Name of function you want to call with parentheses and arguments if needed
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition does not allow the code block to be run while function call allows function to be run. Definition requires {} for code block while call requires () for possible argument
Why are function parameters useful?
Function parameters are useful when replacing values to a function
Why do we log things to the console?
To check our mistakes in javascript by checking the console output and help debug
What is a method?
A method is a function which is a property of an object.
How is a method different from any other function?
function can be called directly while method uses dot notation with object name and method name
How do you remove the last element from an array?
pop()
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
Math.random()
How do you delete an element from an array?
splice() method
How do you append an element to an array?
push()
How do you break a string up into an array?
split() method
Do string methods change the original string? How would you check if you weren’t sure?
String method cannot be changed. You check by trying it and look for online source like MDN
Roughly how many string methods are there according to the MDN Web docs?
a lot
Is the return value of a function or method useful in every situation?
No, it is not necessary when a return is already given
Roughly how many array methods are there according to the MDN Web docs?
thirty
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
=== (strictly equal to), != (is not equal to), >(greater than), !==, >=, <= (less than or equal to)
What data type do comparison expressions evaluate to?
boolean