10 Tricks And Tips For Beginner JavaScript Developers

mhk tushar
3 min readMay 6, 2021

If you want to be a JavaScript developer, I think these 10 tips and tricks will help you

  1. replace()

If you need something new instead of some old things you can use “replace()”.“replace()” method returns a new string with some or all matches of a pattern replaced by a replacement.

const device = ‘Desktop’;

console.log(p.replace(‘Desktop’, ‘Laptop’));
expected output: “Desktop”

2. toUpperCase()

“toUpperCase()” method usually used to convert a sentence or a whole paragraph from any other case to uppercase. If you want to convert your paragraph into the uppercase form you can use this method.

const sentence = ‘This is a uppercase based sentence’;

console.log(sentence.toUpperCase());
expected output: “THIS IS UPPERCASE BASED SENTENCE.”

3. slice()

If your want to slice a watermelon into many pieces this method definitely helps you. This method extracts a part of a string and returns it like a new string, without changing the original string.

const sentence= ‘I want to be a good web developer.’;
console.log(sentence.slice(10));
expected output: “be a good web developer.”
console.log(sentence.slice(20, 33));
expected output: “web developer”
console.log(sentence.slice(-10));
expected output: “developer.”
console.log(sentence.slice(-14, -11));
expected output: “web”

4. concat()

If your wife quarrel with you. And if you become agitated too close to be your wife, you can use this method. This method helps you a lot. And you can solve your problem easily. This method concatenates the string arguments to the calling string and returns a new string.

const text1 = ‘Hello’;
const text2= ‘World’;
console.log(text1.concat(‘ ‘, text2));
expected output: “Hello World”
console.log(text2.concat(‘, ‘, text1));
expected output: “World, Hello”

5. repeat()

If you are very tired to do work again and again. And you just get rid of this situation. This method will help you. This method constructs and returns a new string that contains the specified number of copies of the string on which it was called, concatenated together.

const task= ‘do the work. ‘;
console.log(task.repeat(3));

expected output: “do the work. do the work. do the work.”

6. reduce()

This method will help you to add many numbers of digits. It is very popular and easy method to do sum. This method executes a reducer function on each element of the array, resulting in a single output value.

const prices = [1, 3, 5, 10];
const reducer = (total, number) => total+ number;
console.log(prices.reduce(reducer));
expected output: 14
console.log(prices.reduce(reducer, 5));
expected output: 19

7. push()

If you want to add a new member in your group as the last member. Without thinking any think you can use this method easily. This method adds one or more elements to the end of an array and returns the new length of the array.

const members = [‘Tushar’, ‘Kholil’, ‘Shorif’];
const newList= members.push(‘Ahmed’);
console.log(newList);
expected output: Array [‘Tushar’, ‘Kholil’, ‘Shorif’, ‘Ahmed’]

8. find()

If you lost your wife in a big fair. Do not panic, I have a method. Using this method you can find your wife easily and quickly. This method returns the value of the first element in the provided array that satisfies the provided testing function.

const player = [‘shakib’, ‘Rakib’, ‘Mustafiz’];
const found = player.find(element => element.length > 7);
console.log(found);
expected output: ‘Mustafiz’

9. filter()

If you have many options, and you want to filter which options will be best for you based on some criteria. This method will be the best for you. This method creates a new array with all elements that pass the test implemented by the provided function.

const city= [‘Dhaka’, ‘Delli’, ‘Islamabad’, ‘London’, ‘New York’, ‘Dubai’];
const result = city.filter(city=> city.length > 6);
console.log(result);
expected output: Array [“Islamabad”, “New York”]

10 .forEach()

If you are an examiner. One day you called an interview. And many contestants come for the interview. In this situation, you can use “forEach()” method and you can take the interview one by one.

const students = [‘sahin’, ‘rafiq’, ‘sofiq’];
students.forEach(element => console.log(element));
expected output: “sahin”
expected output: “rafiq”
expected output: “sofiq”

--

--