javascript-methods Flashcards
Why do we log things to the console?
To make sure things are working as intended and to troubleshoot
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?
A method is a function that is associated with an object, whereas a function is a standalone piece of code that is not associated with any particular object
How do you remove the last element from an array?
pop() method
How do you round a number down to the nearest integer?
Math.floor() method
How do you generate a random number?
Math.random()
How do you delete an element from an array?
splice() takes 2 arguments - the index to be deleted , and the number of items to delete. shift() and pop()
How do you append an element to an array?
push() , the argument will be added to the end of the array
How do you break a string up into an array?
split() takes a string as the argument and splits it into and array of substrings
Do string methods change the original string? How would you check if you weren’t sure?
Most string methods in JavaScript do not modify the original string. Instead, they return a new string that contains the result of the operation.
To check whether a string method modifies the original string or not, you can look at the documentation for the method.
You can also test the method by using it on a string and checking the value of the string before and after the method is called
Roughly how many string methods are there according to the MDN Web docs?
50
Is the return value of a function or method useful in every situation?
The return value of a function or method is not always useful in every situation. In some cases, the return value may not be needed at all, and the function or method can be called simply for its side effects (e.g., printing to the console, modifying an object, etc.). In other cases, the return value may be useful in some situations but not in others, depending on how the function or method is being used.
Roughly how many array methods are there according to the MDN Web docs?
40
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN