Basic concepts about JavaScript String Values that you should know as a beginners

Before covering the basic concepts including some methods of string value first, we should know about some core concepts such as:

1. What Is JavaScript?

JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. JavaScript defines as a scripting language or programming language that helps you to implement web pages. JavaScript makes web pages interactive and helps in making web pages dynamic and user-friendly. Its syntax is based on the Java and C languages. JavaScript also supports functional programming.

2. Types of Values in JavaScript

Like another language JavaScript also contain different types of value. They are

  • Number
  • String
  • Boolean
  • Function
  • Object
  • Symbol

Besides all of these null, undefined, Array Date, RegExp also is included.

3. Variables

Exploring JavaScript becomes too difficult without knowing the types of variables In JavaScript, variables are declared using normally three keywords and they are

  1. const
  2. let
  3. var

const: We declare a variable as const when there is no need to change its value. On the other hand, we can compare the const type variable with a constant or a fixed value that will never be changed. As if the value of gravity is a const type variable. Example: const g = 9.8

let : When we declare a variable as let it's mean the value is changeable. Example: As we have declared, we can use let inside a loop for ( let i = 0; i<5 ; i++){}

Var: Var is the common declared keywords in JavaScript. Like the other two types of variables, var doesn't contain such restrictions. It's available and accessible from inside a function and also outside a function.

Example: for (var i =0; i<5 ; i++){ the variable i is accessible from here } the variable i is accessible from outside the loop also.

Now we are going to describe some basic concepts of javascript such as types of values and some of their use that you should know.

4. String

Basically, String is used to represent a sequence of characters. It represents data in text form. The string contains some operations and methods such as length, concatenate substring(), etc.

The way of declaring a string is const name = "Moon";

Here, we are going to describe some method on string

5. charAt()

this chartAt() method basically return a new string according to a index number of a string. Usually in the case of chartAt() method we pass the index number as a parameter through this method.
chartAt(index)

As we know basically index number starts from 0. In a string index number is counted from left to right. Suppose we have a string such as const name = "John". If we counted it normally we will say it contains 4 characters such as J(1), O(2), H(3), N(4). It's true but in the case of indexing, we always have to start counting from the 0 position. So now you know the correct way to count index no is

J(index 0), O (index 1), H(index 2), N(index 3).

Remember that if the index is out of range chartAt() returns an empty string and if no index is provided to chartAt() by default it will return 0

Example:

stringchart.PNG

outputChart.PNG

6. concat()

Basically, concat() is used to add two strings. On the other hand, we can describe it like this, concat() used to concatenates two strings and return a new string value. But the new string and original string don't affect each other. If the arguments that we will pass through the method is not a string it will be converted into a string before concatenating.

Example

conCat.PNG

Concat2.PNG

7.includes()

includes() helps to find out a string from another string and it returns true if the value found else returns false.

Example

includes.PNG

includes1.PNG

8.replace()

replace() helps in replace a specific string that we will pass through this method and return a new string. But it always replaces the first founded matching string another matching content is ignored.

Example

replace.PNG

replace1.PNG

9.toLowerCase()

The toLowerCase() method always returns the selected string value by converting them into the lower case without affecting the main values of that selected string.

Example:

lower.PNG

lower1.PNG

10.toUpperCase()

We can compare this method with toLowerCase() but the difference is it always returns the selected string value by converting them into the upper case without affecting the main values of that selected string.

Example

upper.PNG

upper1.PNG