0% found this document useful (0 votes)
8 views11 pages

Modules

The document contains JavaScript code snippets demonstrating the use of core and local modules. It includes examples of calculating area using both immediate function execution and a named function, as well as a library module for multiplication and division. The main module imports the library and logs the results of the operations and a constant number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Modules

The document contains JavaScript code snippets demonstrating the use of core and local modules. It includes examples of calculating area using both immediate function execution and a named function, as well as a library module for multiplication and division. The main module imports the library and logs the results of the operations and a constant number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Modules

1. Core modules
2. Local modules
var length=10;
var width=20;
var area;
area=length*width;
console.log(area);
var length=10;
var width=20;
var area;
(function(){area=length*width;})();
console.log(area);
var length=100;
var width=20;
var area;
function area()
{area=length*width;
return area;}
console.log(area());
lib.js
function multiply(a,b)
{ return a*b; }
function divide(a,b)
{ return a/b; }
const number=30;
module.exports={multiply,divide,number}

main.js
const lib=require('./lib');
const result=lib.multiply(5,6);
console.log('The answer is: '+result);
const result1=lib.divide(50,5);
console.log('The answer is: '+result1);
console.log(lib.number);

You might also like