Frequently, we are thrown with a question where the interviewer expects us to make a nested array to a single array (in other terms, flatten an array). Although we have an existing Array method to flatten the array but sometimes they expects us to write our own implementation. …

Today I will inform about some npm CLI shorthand commands that we basically encounter in our daily development activities. Below are few shorthand npm CLIcommands

Install a package

## Longhand npm install package-name## shorthandnpm i package-name

Install a package globally

## Longhandnpm install --global package-name## shorthand

Hoisting is a default behaviour in JavaScript where all the declarations (variables & functions) are moved to the top of the current scope. I’m gonna discuss on variable hoisting today.

Let’s understand the variable hoisting with the below sample.

a = "Hello";console.log(a); // Hello var a;

We can see “Hello” on the console even though we declared ‘a’ in the end. Well, This is where hoisting comes into play. By default, JavaScript moves the declarations at the top while execution, and it is initialized. This is ‘Variable Hoisting’

Let’s look into another example.

console.log(a); //undefinedvar a = "Hello";

We see “undefined” in the console. But Why ?

This is because by default JavaScript moves only the declaration at the top and not the ‘initialization’

Thanks for reading this story.

Today I’m gonna write a small article on some alternative way on few ways of writing JavaScript codes.

The old way to convert Number to String/String to Number

let num = 10; 

let newNum = num.toString();

let str = '10';

let strNum = Number(num);

An alternative way to convert Number…

Today, I will discuss some shorthand techniques for regularly used syntax to ace an interview and save our time while writing code.

Sum all the values from an array :

My initial instinct was to use a loop, but that would have been wasteful.

var num = [3, 5, 7, 2]; 

var sum = num.reduce((x, …

Today we gonna discuss the flat() method in JavaScript which can be a part of the interview in the way to becoming a JavaScript developer.

The flat() method is used to flatten the array of arrays. The process of flattening depends on the depth of the array we want to flatten.

Syntax And Return Type 

flat(depth) :—  The depth level specifies how deep a nested array structure should be flattened. Default value is 1.
Return Type — A new array with sub-array elements concatenated into itExamples

let arr1 = [1,2,[3,4,[5,6,]]];

arr1.flat(1) // [1,2,3,4,[5,6]];

arr1.flat(2) // [1,2,3,4,5,6];

arr1.flat(0) // [1,2,[3,4,[5,6]]];

Hope this article may helpful to all !!

Often, JavaScript developers are found encountering the above question in their interviews. Let me tell you, both are ways to create functions, and looks the same. There is a slight difference in them. Let’s understand the difference to have a clear picture of the 2 terminologies.

Function Statement — When…

Rakesh Kumar Shaw

Associate Consultant @Capgemini, India

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store