How to use JavaScript variable names with strings?

Today I will explain how to use javascript variable names with strings. In last session I explained how to create java script variables Previous Article
Now using variable how we can access the length of the variable; let’s check the below

Var  Largedata = “My Name is EknowledgeTree”; 
//to calculate the length of the string we can use length property to display the length

Largedata.length; //which displays the string length

Now using length property we can compare the string length.let check it below


Var  largedataone = ”mynameiseknowledgetree”;
Var largedatatwo = ”getlatestarticlesateknowledgetree”;

Largedataone.lenght > largedatatwo.length
//here it will check whether the condition true or false and writes the output.

Here in the string character has position numbered index starts from “ 0”

 Var  largedataone =”Mynameiseknowledgetree I post new articles!”;

//Here the first character “M” is indexed as zero and after the long sentence there is space as indexed as 23 and last symbol “!” as 42.

Largedataone.length  // output 43

Since the index starts from zero ,but length value will always be one more then the last index.
Finding specific character using charAt() method .

Example below

Var  smalldata = “My Name is  Joe”;

Smalldata.charAt(6); //which will return output as “e”

Now we will see how to concatenate two strings in javascript


Var message=”my name is joe,I am at the age ”;
Var age=28;

Var displayresults = message + ” of ”  + age;
//Now the above example returns the output message as below

// Output -- > My  name is joe, I am at the age of 28

Thanks for reading this article.

Leave a Reply