- Form and submit: if it is form you should listen to submit—event and not click.
- this.querySelector('[name=item]') So if we have form like this:
var input = document.querySelector('.js-it'); var inputValue = input.value;
or using this and parthensis:var input = (this.querySelector['name=it']).value;
- plates=[]: We have function
function populateList(plates=[], plateList){ //code here }
plates=[] is an empty object and if we forget to pass something in, it won't broke our JavaScript - .map(): creates from one array another array.
- .join(''): returns .map() array as a string.
- will still be checked— any existence of attribute checked will check it.
- localStorage accepts only strings. If it's something else in Console->Application-> Local Storage you'll see [object Object]. It can be stringified:
localStorage.setItem('items', JSON.stringify(items));
- JSON. parse() is opposite to JSON.stringify(), itparses string to origin value or object.
- setting value as condition:
const items = JSON.parse(localStorage.getItem('items')) || [];
JavaScript30—Day 15
JavaScript30 is 30-day vanilla javaScript coding challenge by Wes Bos (@wesbos).
The purpose of these posts is to reflect my troubles and moments of ahhaa.
Lessons from Day 15 — LocalStorage and EventDelegation:
Demo - Day 15