TypeScript Deck Flashcards
Why do we log things to the console? (Methods Topic)
to let us see our code and the data we are working with
What is a method?
a method is a function that is attached to an object in the form of a property. another way of saying this is that a method is a function that is a property of an object. method is a property of our object.
How is a method different from any other function?
methods belong to objects specifically
How do you remove the last element from an array?
using the pop method. its written as pop()
How do you round a number down to the nearest integer?
using the Math method. it is Math.floor()
How do you generate a random number?
using the Math method. it is Math.random()
How do you delete an element from an array?
using the pop() method
How do you append an element to an array?
using the push() method
How do you break a string up into an array?
using the split() method, using a specified separator string to determine where to make each split
Do string methods change the original string? How would you check if you weren’t sure?
string methods do NOT change the original string. you must assign the result of a method call to a new variable in order to store the mutate string. if you aren’t sure you can check the console.log()
Is the return value of a function or method useful in every situation?
no, because you have two different types of functions. some that do things and others that don’t
How do you get a collection of an objects keys?
by using the object.keys() method. this returns an array of a given object’s own property names
How do you get a collection of an objects values?
by using the object.values() method. this returns an array of a given object’s property values
How do you get a collection of both an objects keys and values?
by using the objects.entries() method. this returns an array of the objects’ property names and their values
Give 6 examples of comparison operators. (Conditionals Topic)
equal ==, not equal !=, strict equal ===, strict not equal !==, greater than >, less than <, greater than or equal >=, less than or equal <=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if
statement?
to check if a condition is true
Is else
required in order to use an if
statement?
no, it is optional
Describe the syntax (structure) of an if
statement.
if (boolean expression) then we open a code block that executes if the condition is true
What are the three logical operators?
logical AND (&&), logical OR (||), logical NOT (!)
How do you compare two different expressions in the same condition?
using the logical operator
What is the purpose of a switch
statement?
to compare a collection of conditions or cases that need to be checked against each other. it is also more readable and user-friendly compared to else/if statements
Is a default
clause required in order to use a switch
statement?
no, it is optional but it is a good way to handle a catch all in case any previous clauses did not execute