devwiki:javascript

This is an old revision of the document!


Javascript Advance and Modules

  • as javascript program becomes complex, it has new concepts of modules, (like python module, a library of functions)
  • as javascript is inside different browser, means it needs browser support, modern new browser has support new feature of js, but js need to tell them, how modern this JS code is, like type attribute.
    <!doctype html>
    <script type="module">
      // note: module need browser access via http, not file:///
      import {sayHi} from './say.js';
      document.body.innerHTML = sayHi('John');
    </script>
  • new let vs var
    let a = 1 // local block accessible only
    var b = 1 // global accessible
  • unpack assignment (destructuring assignment, as from js1.7 = ES6)
    [a, b] = [10, 20]; // Destructuring arrays
    // same as  pyhton: a,b = [10,20]
    const Zell = {
      firstName: 'Zell',
      lastName: 'Liew'
    }
    let { a, b} = Zell // destructuring objects

Useful code

  • devwiki/javascript.1630317438.txt.gz
  • Last modified: 2021/08/30 09:57
  • by ying