JS week 1 day 3 Flashcards
Why do we log things to the console?
The JavaScript console is a debugging tool. It is where the browser prints errors and warnings as they occur in your JavaScript code.
How is a method different from any other function?
A function lives on its own. A method is a function associated with an object property. A function can be called directly by its name. A method consists of a code that can be called by the name of its object and its method name using dot notation or square bracket notation.
How do you remove the last element from an array?
using .pop method
How do you round a number down to the nearest integer?
using Math.floor method
How do you round a number down to the nearest integer?
using Math.floor() method
How do you generate a random number?
using Math.random() method
How do you delete an element from an array?
using .splice method()
How do you append an element to an array?
using .push() method
How do you break a string up into an array?
using .split() method
Do string methods change the original string? How would you check if you weren’t sure?
The split() method does not change the original string because JavaScript strings are immutable. To check we can either check documentation or use console.log()
Roughly how many array methods are there according to the MDN Web docs?
38 methods
Is the return value of a function or method useful in every situation?
Some functions don’t return any value (For example: void or undefined). Generally, a return value is used where the function is an intermediate step in a calculation of some kind.
Roughly how many array methods are there according to the MDN Web docs?
36 methods
Give 6 examples of comparison operators.
===, >, =, <=, !===
What is the purpose of an if statement?
if statements are used to check if condition is true or false.