Some JavaScript basic thing that you need to visit everyday.

MeHeDi HaSan Khairul
3 min readMay 5, 2021

Hello ! I’m MeHeDi HaSaN Khairul. Today I will talk about 10 JavaScript facts that you need to know.

JavaScript Array

Suppose you want to store some data that is your friend’s name. In these situations what will you do? Separate variable for each friend like this..

Example:

const friend1 = "BatMan";const friend2 = "FatMan";const friend3 = "CatMan";const friend4 = "RatMan";

In this case I want to store my whole university friends name.

What can I do in this situation. It is not convenient for me to write variables separately for everyone. On the other hand the data is almost similar, all are human names. In those situations we found a solution called JavaScript Array.

Array is a special type of Object in JavaScript. Objects means an object is a collection of properties, that means if you are an object you have hands, eyes, nose, hair, legs all are called properties. Similarly arrays have some properties. Which is used for access in array data.

Two ways to declare arrays in JavaScript.

First one is rarely used. But it’s good to know.

const friendlist = new Array ("Batman", "CatMan", "FatMan", "RatMan");console.log(friendlist);

Another Way to declare arrays in JavaScript.

const friendsName = ["Batman", "CatMan", "FatMan", "RatMan"];console.log(friendsName);

JavaScript String

JavaScript strings typically store a bunch of characters for later use. Exp: “Jhankar Mahbub”

String is some character inside the quotation. You can use single or double quotations.

Example:

‘Jhankar Mahbub’;
“Jhankar Mahbub”;

You can use quotations inside the string as many times as you like, until the first and last quotations match.

Example :

“It’s rainy day”;“The best teacher i have ever seen is ‘Jhankar Mahbub’ also a good person”

String Length

The length property returns the length of a string:

const alphabet = "ABCDEFGH";
const count = alphabet.length;

Find a String in a String

The indexof() method returns the index of the position of the first number of a specified text in a string

Example:

const text = “ I am from ‘Bangladesh’.”;const position = text.indexOf(“Bangladesh”);

JavaScript Number Method

Number methods help you to work with numbers.

Besides the primitive number type, JavaScript also provides the Number reference type for numeric values.

To create a number object, you use the number constructor and pass in a number as

Example:

const numberObject = new Number (20);
console.log(numberObject.valueOf());

Methods:

  • The Number() method converts a string into a number.

Example:

const x = “10”;
const num = Number(x);
console.log (num); = output: 10
console.log(num * 10); = output: 100
  • The toString() method returns a number as a string value.

Example:

const x = 10;
const num = x.toString();
Console.log (num); = output: “10”
  • The parseInt() method is almost similar to the number method parseInt() formats a string into an integer number.

Example:

const x = “10.99”;const num = parseInt (x);
  • The parseFloat() method parses a string value and returns the number with its decimal value.

Example:

const x = “10.99”;
const num = parseFloat (x);
Console.log (num); = output: 10.99

--

--