Talking about JavaScript, if you understand how much fun!

Md. Injamul Alam
4 min readMay 5, 2021

--

Talking about JavaScript

In this article, I am discussed about fundamental elements of JavaScript. There are:

String, Number, Math, Array

Let’s know about the Strings:

Strings are text, written within single(‘any text ’) or double(“any text ”)quotes:

Syntax:

“Hello World”

‘Hello JavaScript’

`This is template string`

How to creates strings:

We have to declare it as primitives, or as object using the constructor String()

Example :

const firstEmployee = ‘Md. Injamul Alam’;

const secondEmployee = “Md. Abdur Rahim”;

const thirdEmployee = `Jahidul Islam`; //this is template string

const objectString = new String(“This is a string object”);

Properties

If we want to know or find the length of any string, we have to use the length property of the string.

For example:

const Name = ‘Injamul Alam’; // This is a string

// finding this length of the string should be used .length property:

console.log(‘Your name length is’, Name.length);

// Output: Your name length is 12

Example of String property

Methods

.charAt() :

This method used for finding or access any character of the string.

Syntax:

string.charAt(position)

Parameter

position, if we can not declare any position or index it will be provided a default index or position value of 0.

For example:

const Name = ‘Injamul Alam’; // This is a string

// finding or access an individual character in a string should be used charAt(position) method:

console.log(‘The character without declare position ‘, Name.charAt());

// Output: by default 0 position character in the string is I

console.log(‘The character at position 5’, Name.charAt(5));

// Output: 5th position character in the string is u

// declare a position :

const position = 8;

console.log(‘The character at position 6’, Name.charAt(position));

// Output: 8th position character in the string is A

Example of .charAt() method

.concat() :

This concatenate method used for connect two or more strings and returns a new one string.

Syntax:

concat(string1)

concat(string1, string2)

concat(string1, string2, …, stringN)

Parameters:

stringN, parameter is concatenate to more strings.

For example:

const firstName = ‘Md. Injamul’; // This is a first string

const secondName = ‘Alam’; // This is a second string

const fullName = ‘My full name is ’; // This is a third string

// .concat() method used for connect two or more string and returns a new string:

console.log(firstName.concat(‘ ’, secondName));

// output: “Md. Injamul Alam”

console.log(fullName.concat(firstName,‘ ’, secondName));

// output: “My full name is Md. Injamul Alam”

Example of .concat() method

.includes():

This method is used to search or find a string within another string and it returns ‘true’ if the search string is found anywhere within the given string otherwise returns ‘false’.
It is case-sensitive and it does not change the value of the original string.

Syntax:

includes(findString)

includes(findString, index)

Parameters:

findString, It is required to search the string within the main string.

index, This is an optional parameter and its default value is 0. At which position to start the search of a string.

For example:

// String.includes() method without arguments:

let mainString = ‘My name is Md. Injamul Alam’;

let findString = ‘name’;

console.log(`The searching string ‘${findString}’ ${mainString.includes(findString) ? ‘is’ : ‘is not’} in the main string.`);

// String.includes(findString, index) method with arguments:

console.log(`The searching string ‘${findString}’ ${mainString.includes(findString, 8) ? ‘is’ : ‘is not’} present at the 8th position of the main string.`);

// Check case-sensitivity:

let check = ‘Case-sensitivity’;

console.log(`Here ‘C’ is capital letter and into the includes method string ‘c’s in small letter, that’s why the result is ${check.includes(‘case-sensitivity’) ? ‘TRUE’ : ‘FALSE’}.`);

Example of .includes() method

.endsWith():

This method is used to determines whether a string ends with the characters of a specified string or not and it returns ‘true’ if the search string is found at the end of the string otherwise, it returns ‘false’.

It is case-sensitive and it does not change the value of the original string.

Syntax:

endsWith(findString)

endsWith(findString, length)

Parameters:

findString, It is required to search at the end of the string within the main string.

length, This is an optional parameter and it specifies the length of the string that will be searched and If this argument is not provided, the endsWith() method will search the full length of the string.

For example:

// String.endsWith() method without arguments:

let mainString = ‘My name is Md. Injamul Alam’;

let findString = ‘Alam’;

console.log(`${mainString.endsWith(findString) ? ‘TRUE’ : ‘FALSE’}`);

// String.endsWith(findString, length) method with arguments:

console.log(`${mainString.endsWith(findString, 26) ? ‘TRUE’ : ‘FALSE’}`);

// Check case-sensitivity:

let check = ‘This method is Case-sensitivity’;

console.log(`${check.endsWith(‘case-sensitivity’) ? ‘TRUE’ : ‘FALSE’}`);

Example of .includes() method

.indexOf():

This method is used to returns the first index of occurrence of a given value in the string, or -1 if it is not present.

It is case-sensitive and it does not change the value of the original string.

Syntax:

string.indexOf(findString)

string.indexOf(findString, startingIndex)

--

--