Web Dev
create a variable for fields in the html
input type="submit" value="Submit guess" class="guessSubmit" />
const guessSubmit = document.querySelector(".guessSubmit");
guessSubmit.addEventListener("click", checkGuess);
const output = document.querySelector('.output');
const para = document.createElement('p');
para.textContent = "Paragraph";
bird = {species: 'Bird'}
const filtered = cats.filter((cat) => cat.startsWith("L"));
localStorage.setItem("name", myName);
const name = localStorage.getItem("name");
localStorage.removeItem("name");
// clear all
localStorage.clear()
- Javascript stores variables in the DOM - the representation of HTML nodes.
- React stores variables in Javascript objects, which can be updated as they change on the page
so React will be better for pages with constantly changing user inputs
doSomething()
.then((result) => doSomethingElse(result))
.then((newResult) => doThirdThing(newResult)) // newResult is the result of doSomethingElse
.then((finalResult) => {
console.log(`Got the final result: ${finalResult}`);
})
.catch(failureCallback);
as a good general rule of thumb, always return the contents of a promise
preventDefault is an event listener stops default behaviors of events. Ex: page reload on form submit