Tag Archives: map

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
  1. Form and submit: if it is form you should listen to submit—event and not click.
  2. this.querySelector('[name=item]') So if we have form like this:
    We can grab input value like this:
    var input = document.querySelector('.js-it');
    var inputValue = input.value;
    
    or using this and parthensis:
    var input = (this.querySelector['name=it']).value;
    
  3. 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
  4. .map(): creates from one array another array.
  5. .join(''): returns .map() array as a string.
  6. will still be checkedany existence of attribute checked will check it.
  7. 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));
    
  8. JSON. parse() is opposite to JSON.stringify(), itparses string to origin value or object.
  9. setting value as condition:
    const items = JSON.parse(localStorage.getItem('items')) || [];
    
Day 15 code on github.