Skip to main content

Posts

module.exports vs exports in Node

You can export functions and values from a module by either using   module.exports: module . exports = { value1 , function1 } or by using  exports: exports . value1 = value1 exports . function1 = function1 So what's the difference? Exporting values with just the  exports  keyword is a quick way to export values from a module. You can use this keyword at the top or bottom, and all it does is populate the  module.exports  object. But if you're using  exports  in a file, stick to using it throughout that file. Using  module.exports  is a way of explicitly specifying a module's exports. And this should ideally only exist once in a file. If it exists twice, the second declaration reassigns the  module.exports  property, and the module only exports what the second declaration states. So as a solution to the previous code, you either export like this: // ... exports . value1 = value1 // ... exports . function1 = function1 ...
Recent posts

sum(1)(2)(3)(4)..( n)() in JavaScript

  console.log('sum(1)(2)(3)(4)..( n)()'); // Solution 1: let sum = function (a) { return function (b) { if (b) { return sum(a + b); } return a; } } let result = sum(1)(2)(3)(4)(5)(); console.log(result); // 15 // Solution 2: let sum = (a) => (b) => (b) ? sum(a+b) : a; let result = sum(1)(2)(3)(4)(5)(); console.log(result); // 15

Closures in JavaScript

  A  closure  is the wrapping up of function and it's  surrounding  variables with in a function or lexical scope.  In the other way we can say, we can access the outer function scope from the inner function.  So we can say, closure are created when functions are created.  Example of closure:   function outerMethod() {      var name = 'Hello World';      function innerMethod() {           console.log(name);      }       innerMethod(); } outerMethod(); So output of the above example is: Hello World Here the name variable is in the scope of outer function and we are accessing from the inner function. This is closure.  More understand about closure with it's lexical scoping:    In JavaScript we can return a function within another function. Please check the below example. function outerMethod() {      var name = 'Hello World'; ...

How JavaScript Works ?

Any JavaScript code runs on any browser. How JavaScript code run in a browser ? Because every browser has JavaScript engine. As a google chrome has V8 engine, Mozilla Firefox has SpiderMonkey and etc . So when any JavaScript code comes to the browser then Parser will execute the code line by line and produce a data structure called Abstract Syntax Tree (AST). If Parser produce the AST then the code translate to Machine Code using of AST. Once the code converted into Machine Code then the actual code will run.       

Angular Chart Builder

This is my first angular library, named angular-chart-builder . It's a license free npm library. Anyone can install and integrate this library to there own angular project. Now the angular-chart-builder library have two types of charts that is Progress Bar and Pie Chart .   To get the library, please check the below url:    https://www.npmjs.com/package/angular-chart-builder    

An Introduction to JavaScript

Let’s see what’s so special about JavaScript, what we can achieve with it, and which other technologies play well with it. JavaScript  was initially created to  “make web pages alive” . The programs in this language are called  scripts . They can be written right in a web page’s HTML and run automatically as the page loads. Scripts are provided and executed as plain text. They don’t need special preparation or compilation to run. Today, JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called the JavaScript engine. The browser has an embedded JavaScript engine.