Two commonly known ways to execute a script in Node.JS are using eval () function or running it using VM module. Lets see this through an example: [js] var vm = require('vm'); this.name = "Sakshi"; var script = "this.name = 'Tyagi'", withVM, withEVAL; withEVAL = eval(script); console.log("withEVAL...
In extension to my previous blog on Event Emitters Event Emitters In Node.JS, here we will see some variations in implementing Event Emitters. We can bind more than one listeners to an event. For example: [js] var events = require('events'); var eventEmitter = new events.EventEmitter(); var printFruit = function printFruit() { ...
We can create constants in JavaScript using 'const' keyword. [js] const name = 'Sakshi' console.log(name) [/js] This will print: Sakshi Now, if we try to change or re-initialize 'name' constant, the value will not change. [js] const name = 'Hello' console.log(name) [/js] This will again print: Sakshi Compatibility: 'const'...
Event Emitters are used to create and manage our own events and trigger them accordingly. We can bind listeners and emit those events whenever required. Example : [js] var events = require('events'); var eventEmitter = new events.EventEmitter(); eventEmitter.on('Morning', function welcomeMessage() { console.log('Good...
MongoDB provides several ways of computing the average value of a group in a collection. One of the simplest ways of determining average is using the method db.collection.group(). The method db.collection.group() bunches the documents of a collection on the basis of the keys mentioned and executes aggregation functions on them. This...
Most people using JavaScript misunderstand the difference between ‘null’ and ‘undefined’. An unclear distinction between these two entities can lead to grave issues when using ‘null’ and ‘undefined’ in test cases. A variable is said to be ‘undefined’ if it has been declared, but no value has been given to it....
Arrays in JavaScript are daunting and particularly difficult in nature. The fundamental reason for making this statement is that JavaScript does not provide as many functions/methods for array operations as several other languages do. As a result, an array operation as simple as removing duplicate elements from an array may also be...