Javascript Basic Concepts

Milton Biswas
3 min readMay 5, 2021

Javascript is a scripting or programming language that converts our website dynamic and interactive. It is also a server-side scripting language inserted into HTML pages and is understood by web browsers.

Here are 5important things for everyone to know about JavaScript-

  1. Variable
  2. Array
  3. Condition
  4. Loop
  5. Function

Today I discuss String, Number, and Array

1.String.concat()
concat method is adding two string
const str1 = 'Azizul';
const str2 = 'Islam';

console.log(str1.concat(' ', str2));
// expected output: "Azizul Islam"

2.String.toUpperCase()
str.toUpperCase() method converts the string to Upper case. This method does not affect any of the special characters, digits, and the alphabets that are already in the upper case.
const sentence = 'I love javascript programming';

console.log(sentence.toUpperCase());
// expected output: "I LOVE JAVASCRIPT PROGRAMMING"

3.String.replace()
String.replace() method changes any string by another string. It takes two parameters which the first parameter is how you want to change and the second parameter is where you want to change and gives the new string

const replaceStr = 'I am a javascript developer';
console.log(replaceStr.replace('developer', 'programmer'));
// expected output: "I am a javascript programmer"

4.Math.ceil()
Math.ceil() is a method which is round any number up to the next large number.

console.log(Math.ceil(.48));
// expected output: 1

console.log(Math.ceil(4));
// expected output: 4

console.log(Math.ceil(7.004));
// expected output: 8

console.log(Math.ceil(-7.004));
// expected output: -7
5.Math.floor()
Math.floor() is a method that is round any number less than or equal to the given number.

console.log(Math.floor(5.95));
// expected output: 5

console.log(Math.floor(5.05));
// expected output: 5

console.log(Math.floor(5));
// expected output: 5

console.log(Math.floor(-5.05));
// expected output: -6

6.Math.random()
Math.random() is a method that is generated always at random value. Below the second example when we multiply any number by a random method then it returns always a random value by limitation given number. Basically, it use raffle draw programme

console.log(Math.random());

const number = 20;
console.log(Math.random() * number);

7.arr.map()
arr.map() method basically returns a new array and this method returns value, index number and array
const arr = [1, 10, 15, 18, 25, 9];
arr.map(function(value, index, arr){
console.log(value, index, arr)
})
// expected output:
1 0 [ 1, 10, 15, 18, 25, 9 ]
10 1 [ 1, 10, 15, 18, 25, 9 ]
15 2 [ 1, 10, 15, 18, 25, 9 ]
18 3 [ 1, 10, 15, 18, 25, 9 ]
25 4 [ 1, 10, 15, 18, 25, 9 ]
9 5 [ 1, 10, 15, 18, 25, 9 ]

8.arr.foreEach()
arr.foreEach() is a method which is returns the value and array
const arr = [1, 10, 15, 18, 25];
arr.forEach(num => {
console.log(num, arr);
})
// expected output:
1 [ 1, 10, 15, 18, 25 ]
10 [ 1, 10, 15, 18, 25 ]
15 [ 1, 10, 15, 18, 25 ]
18 [ 1, 10, 15, 18, 25 ]
25 [ 1, 10, 15, 18, 25 ]

9.arr.reduce()
arr.reduce provides two parameters which is previous value and current value

var arr = [1, 2, 3, 4, 5, 6];

var sum = arr.reduce(function(previous, current){
return previous + current;
})
console.log(sum) // expected output:21

var multi = arr.reduce(function(previous, current){
return previous * current;
})
console.log(multi) // expected output:720

10.arr.slice()
arr.slice is a method of that cuts certain parts from an array.The specific part of this method can be determined by the index
const arr = [10, 15, 20, 25, 30];

console.log(arr.slice(2));
// expected output: Array [20, 25, 30]

console.log(arr.slice(2, 4));
// expected output: Array [20, 25]

--

--

Milton Biswas
0 Followers

My name is Azizul Islam Milton. I am a javascript developer. I love javascript language and also love React js very much.