In JavaScript, there’s many different ways of doing something. This is both a good thing and a bad thing. To the newcomer this is definitely a bad thing, as it means not only more things to learn, but more little caveats and more places to go wrong. And so it is with declaring fu...
In this tutorial let us look at different methods to check if a number is prime or not in JavaScript and understand where exactly are these useful. A prime number is a natural number greater than 1 that cannot be obtained by multiplying two smaller natural numbers. All the other non prime...
Learn how to reverse an array efficiently using JavaScript. Follow our step-by-step guide for reversing arrays with built-in methods or custom implementations.
We can use various methods to work with the keys of an object, such as Object.keys(), which returns an array of the object’s own enumerable string-keyed property names. How to rename an object key in JavaScript? There’s no built-in function to rename object keys in JavaScript. Howeve...
Using this method each instance of theHedgehogclass has its own instance of thethis[speed]variable which is still accessible to other methods in the class thanks to thespeedsymbol defined at the top. Symbols are not accessible when using dot notation and iterating over the collection of objects...
JavaScript Constructor Function You can create an object in three different ways: Using object literal By creating instance of Object directly By using constructor function Example 1: Using object literal // program to create JavaScript object using object literalconstperson = {name:'John',age:20,...
An object is a group of data that is stored as a series of name-value pairs encapsulated in one entity. In this article, we will learn different ways to create an object in JavaScript.
In this blog post, I take a different approach to explaining this in JavaScript: I pretend that arrow functions are the real functions and ordinary functions a special construct for methods. I think it makes this easier to understand – give it a try.Two...
Object: Shadow copy: 1. object.assign: constnewObj = Object.assign({}, obj, {prop:'newProp'}) 2. spread opreator: constnewObj ={ ...obj } Deep copy: From lodash: constnewObj = _.cloneDeep(obj) From Ramda: constnewObj = R.clone(obj); ...
Methods to Exit in Node.js Exit in Node.js means stopping the server or exiting all the running processes. In this tutorial we will cover two ways to exit in Node.js, first using keyboard shortcut keys and second using methods from the Node.js global process module. Let’s look at the...