Which fundamental things of JavaScript you should know as a beginner?

Al Mahamud Murad
5 min readMay 5, 2021

Nowadays, JavaScript is the most popular programming language in the world. If you think you start learning javascript. It would be best if you understood the basics of javascript. In this article, I am going to share some knowledge about the fundamental of javascript. Mainly javascript stands for seven types of Data.

JavaScript types are:

  • Number
  • String
  • Boolean
  • Symbol
  • Object ( Function , Array , Date, RegExp )
  • null
  • undefined

In this article, we discuss string, Number, and Array.

String: String means to store any characters or text inside double or single quotes. Any number or text should be a string if they are inside double or single quotes.

JavaScript String Methods:

String.length:

String.length() method use to find the length of a string, use the built-in length property.

const name = "Hey I am Murad";
console.log(name.length)

String.charAt():

The string.charAt() method returns the character at the specified index in a string. The index of the first character is 0, and the second character is 1, and so on. The index of the last character in a string is string.length-1.

const name = "Hello I am Murad";
const result = name.charAt(); //print first character
const result = name.charAt(4); //print 0
const result = name.charAt(string.length-1); //print last character
characterconsole.log(result)

String.concat():

The string.contact() method is used to join two or more strings.

const fristName = "Murad"
const lastName = "Hasan"
const fullName = fristName.conact(lastName)
console.log(fullName)

String.includes():

The string.includes() method determines whether a string contains the characters of a specified string. It always returns true or false value as a result.

const name = "Hi, I am Murad Hasan"
const result = name.includes("Murad") //true
const result2 = name.includes("mahamud") // false

String.endsWith():

Using this method we can determine if a string ends with a character that matches the searched string.

string.endsWith("search");// SYNTAXconst string = "Javascript Strings";
console.log(string.endsWith("s");// true
console.log(string.endsWith("x");// false

String.substring():

This method divides the whole string according to the given starting and ending indexes.

string.substring(start,end);// SYNTAXconst 
str = "JAVASCRIPT";
console.log(str.substring(2,4));// "VA"

string.toLowerCase():

This method turns all the character of a sting to lowercase.

const str = "JAVASCRIPT";
console.log(str.toLowerCase()); // "javascript"

string.toUpperCase():

This method turns all the character of a sting to uppercase.

const str = "javascript";
console.log(str.toUpperCase()); // "JAVASCRIPT"

Number:

Number is one of the data types of javascript and it used to represent and manipulate numbers like 67 or -9, 0.4 .

Number Methods:

Javascript provided some methods to work with Javascript Number.

Math.abs():

The abs() method returns the absolute value of a number.

const number = -4.76
const result = Math.abs(number);
console.log(result)

Math.random():

Math.random() method returns a random number from 0 up to but not including 1.

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

Math.round():

Math.round() method rounds a number to the nearest integer.

const number = Math.round(8.97876);
console.log(number)

Math.sqrt():

Math.sqrt() method use to find the square root of a number.

const number = Math.sqrt(99);
console.log(number)

Array

Before understanding the array methods, we have to understand what array means? In Javascript array refers to a single variable that can contain different elements. Unlike most programming languages, arrays in Javascript can contain a value of different types.

So let’s First take an array as an example and start learning about the methods.

let friends = ["Murad","Joy", "Hillol","Anamul","Rakib"];

Array.length:

array.length is used to find out the length of an array.

console.log(friends.length)// The output will be 5.

Array.pop:

This method is used to remove the last element from the array.

let pop = friends.pop();
console.log(pop);.// Strawberry removed from the last index.
console.log(friends);// ["Murad","Joy", "Hillol","Anamul"]

Array.push:

array.push does the opposite of the pop() method. It inserts an element in the last index of the array.

friends.push("Tunni");
console.log(friends);//["Murad","Joy", "Hillol","Anamul", "tunni"]

Array.shift:

This method removes an element from the first index of the array.

friends.shift();
console.log(friends);// ["Joy", "Hillol","Anamul", "tunni"]

Array.unshift:

This method inserts an element in the first index of the array.

friends.unshift("Murad");
console.log(foods);// ["Murad", "Joy", "Hillol","Anamul", "tunni"]

Array.slice:

array.slice copies the whole array or copies some certain elements of the array and returns a new array. The method can have the following syntax.

array.slice(); // copies the whole array.
array.slice(start); //
copies elements from the start index.
array.slice(start,end); //
copies elements from the start index upto end excluding the element of the end index.let newFriends = friends.slice();
console.log(newFriends); //
["Guava", "Orange", "Banana", "Mango", "Grape"]

Array.splice:

array.splice removes elements from the array or replaces them by adding new elements in place. The method can have the following syntax.

array.splice(start); // removes all element from the starting index.
array.splice(start,deleteCount); // removes element from the starting index equivalent to deleteCount.
array.splice(start, deleteCount, item); // replaces deleteCount element at starting index.foods.splice(2);
console.log(foods);foods.splice(1,2);
console.log(foods);
foods.splice(2,1,"joy");
console.log(foods);

Array. find:

The array.find() method gives the first value that matches the condition.

let numbers = [ 4 , 7 , 9 , 5 , 8 ];
const search = numbers.find(number => number > 6 );
console.log(search); // The returned value is 7 as it's the first one that matches the condition.

Array.sort():

This method returns a sorted array in ascending order.

let numbers = [ 4 , 7 , 9 , 5 , 8 ];
numbers.sort();
console.log(numbers); // [4, 5, 7, 8, 9]

Array. Reverse:

The method returns the reversed array.

let numbers = [ 4 , 7 , 9 , 5 , 8 ];
numbers.reverse();
console.log(numbers); // [9, 8, 7, 5, 4]

Array.indexOf:

This method returns the index of an element. If there are multiple occurrences of the same element, then it returns the first one, and if the element is not present in the array, it returns -1.

let numbers = [9, 8, 9, 7, 5, 4];
console.log(numbers.indexOf(7)); // 3
console.log(numbers.indexOf(9)); // 0
console.log(numbers.indexOf(1)); // -1

Array.join:

This method converts the whole array into a single string separated by a comma.

let numbers = [9, 8, 9, 7, 5, 4];
console.log(numbers.join()); // "9,8,9,7,5,4"

For Details About this things and JavaScript follow the link: https://developer.mozilla.org/en-US/docs/Web/JavaScript

Happy Coding

--

--