11 Concepts That Will Level Up Your JavaScript Skills As a Junior Developer

Nadim Mahmud
3 min readMay 5, 2021

1.String.trim()

The trim() method removes whitespace from both sides of a string.

var str = “ Hello World! “;
alert(str.trim());

2.String.slice()

The slice() method extracts parts of a string and returns the extracted parts in a new string.

let str = ‘The morning is upon us.’
str.slice(-3) // returns ‘us.’
str.slice(-3, -1) // returns ‘us’
str.slice(0, -1) // returns ‘The morning is upon us’

3.String.toLowerCase()

This function converts a string Character to Lowercase Character.

const sentence = ‘The quick brown fox jumps over the lazy dog.’;
console.log(sentence.toLowerCase());
// expected output: “the quick brown fox jumps over the lazy dog.”

4.String.spilt()

Split a string into an array of substrings:

var str = “How are you doing today?”;
var res = str.split(“ “);

5.Number.parseFloat()

function converts a string to a floating number.

parseFloat(51.12) //51.12

6.Math.random()

This example returns a random integer between the specified values. The value is no lower than min (or the next integer greater than min if min isn't an integer), and is less than (but not equal to) max.

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}

7.Math.round()

The math round function returns the value of a number rounded to the nearest integer.

console.log(Math.round(0.9));
// expected output: 1

console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05));
// expected output: 6 6 5

console.log(Math.round(-5.05), Math.round(-5.5), Math.round(-5.95));
// expected output: -5 -5 -6

example

Math.round( 20.49); //  20
Math.round( 20.5 ); // 21
Math.round( 42 ); // 42
Math.round(-20.5 ); // -20
Math.round(-20.51); // -21

8.Array.filter() :

when you working with data,u will must need to filter dta.Array.filter do the task for u.

function isBigEnough(value) {
return value >= 10
}

let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)

The following example returns all prime numbers in the array:

const array = [-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];

function isPrime(num) {
for (let i = 2; num > i; i++) {
if (num % i == 0) {
return false;
}
}
return num > 1;
}

console.log(array.filter(isPrime)); // [2, 3, 5, 7, 11, 13]

9.Array.find()

The find method returns the value of the first element in the provided array that satisfies the provided testing function.

const inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];

function isCherries(fruit) {
return fruit.name === 'cherries';
}

console.log(inventory.find(isCherries));
// { name: 'cherries', quantity: 5 }

Find an object in an array by one of its properties

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12

10.Array.Destructuring()

Don’t be thrown off by JavaScript parameter destructuring! It’s a common way to cleanly extract properties from objects.

const obj = {
name: 'Joe',
food: 'cake'
}const { name, food } = obj;console.log(name, food);

11.Array.reduce()

Array.reduce method call a reducer function and return a single accumulated value to get an array where duplicate items have been removed.

let myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd']
let myOrderedArray = myArray.reduce(function (accumulator, currentValue) {
if (accumulator.indexOf(currentValue) === -1) {
accumulator.push(currentValue)
}
return accumulator
}, [])

console.log(myOrderedArray)

--

--

Nadim Mahmud

My name is Nadim Mahmud. I am a software developer with extensive knowledge in programming, web development, mobile development, and database design.