Skip to content

Instantly share code, notes, and snippets.

@rajpootmohan
Created September 8, 2017 09:23
Show Gist options
  • Save rajpootmohan/2e52ada2dfef8b25f67d9acfa63cfa8e to your computer and use it in GitHub Desktop.
Save rajpootmohan/2e52ada2dfef8b25f67d9acfa63cfa8e to your computer and use it in GitHub Desktop.
Node module export and require
1. FIRST-CLASS FUNCTIONS: Everything you can do with other types you can do with function. Like put them in array, set variables equal to them, etc.
2. AN EXPRESSION: A block of code that results in a value.
5. PRIMITIVE: A type of data that represents a single value. Means no object.
6. PASS BY VALUE VS PASS BY REFERENCE: primitive values work as pass by value but objects work as pass by reference.
7. IMMEDIATLY INVOKED FUNCTION EXPRESSIONS (IIFE): function which is immediatly invoked without affecting any other scope of variables and methods. Syntax is :
var firstName = "Random";
(function(lastName){
var firstName = "Mohan";
console.log(firstName);
console.log(lastName);
})("Singh");
console.log(firstName);
// firstName variable scope would not affect by IIFE.
8. module.exports is what the require function returns.
9. exports and module.exports both are referencing same object.
10. If we assign something using = sign to a variable, then this variable creates new memory with new values and lost previous values;
11. module are parts of v8 engine. But in ES6(2015) introduces module support in JS. So export method defination like
export function greet(){ console.log("es6 xport");}
And how to include in your file is given below:
import * as greetr from 'greet';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment