devwiki:javascript

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 // block scope; local block accessible only
    var b = 1 // function scope; global accessible when global declare, local only when local declare
  • unpack assignment (destructuring assignment, as from js1.7 = ES6)
    [a, b] = [10, 20]; // Destructuring arrays
    // same as  pyhton: a,b = [10,20]
    const my_data = {
      firstName: 'Any',
      lastName: 'One'
    }
    let { firstName, lastName } = my_data // destructuring objects, note the variable name must be same as key name

Useful code

  • devwiki/javascript.txt
  • Last modified: 2021/09/02 09:48
  • by ying