js-102
Version:
JS-102 helps you learn JavaScript (the right way) so that you can confidently use higher-level libraries and frameworks. — Let’s reveal the magic!
48 lines (39 loc) • 1.27 kB
JavaScript
/*
* the devil is in the details
* .--. __--__ (`-') .--. .----. .----.
* | ,|/ _ / ( OO).->/_ | / .. \\_,-. |
* |(_|\_..`--.(,------. | || / \ . .' .'
* ,--. | |.-._) \`------' | |' \ / '.' /_
* | '-' /\ / | | \ `' /| |
* `-----' `-----' `--' `---'' `------'
*
* This project is a part of the “Byte-Sized JavaScript” videocasts.
*
* You can watch “Byte-Sized JavaScript” at: https://bytesized.tv/
*
* MIT Licensed — See LICENSE.md
*
* Send your comments, suggestions, and feedback to me@volkan.io
*/
const util = require( '../lib/util' );
const separator = util.separator;
const log = console.log;
separator();
(function() {
log( 'Hello from an IIFE.' );
}());
{
log( 'A block level code is the same as an IIFE.' );
}
{
const number = ( () => 10 )();
log( `The number is “${number}”.` );
}
separator();
// ## Lessons to Learn
//
// Instead of IIFEs, prefer using modules and block-level scoping with `const` and `let`.
//
// Prefer using CommonJS (i.e. Node.JS-style) for your code; you can always use
// tools like webpack, grunt, browserify, gulp… etc. to bundle them into a code that
// the browser can understand.