JavaScript Basic Concept
Learn basic JavaScript. Today I’m writing some JavaScript codes for learning purposes. Here is how to start learning JavaScript as a beginner.

Let’s start coding practice and learning. I am opening vs code and writing code and share the output here. I will try my best to tell you more in detail. Let’s learn JavaScript basic concept.
- charAt()
const sentence = "Mohammad Shohag";
const index = 9;
console.log(`Character at index ${index} is ${sentence.charAt(index)}`);
Output: Character at index 9 is S
Here charAt is to show you the index character when we input the position. So here I write 9 as the position then it returns output S is the char at this index.
2. concat()
const str1 = ‘Software’;
const str2 = ‘Engineer’;
console.log(str1.concat(‘ ‘, str2));
Output: “Software Engineer”
concat() just concatenates two strings together and returns the new string as the output here.
3. includes()
const sentence = ‘My full name is Mohammad Shohag’;
const word = ‘Shohag’;
console.log(`The word “${word}” ${sentence.includes(word) ? ‘is’ : ‘is not’} available in the sentence`);
Output: The word “Shohag” is available in the sentence
includes checking case-sensitive search if the word is available on this sentence.
4. endsWith()
const str1 = ‘Software Engineer’;
console.log(str1.endsWith(‘Engineer’));
Output: true
const str1 = ‘Software Engineer’;
console.log(str1.endsWith(‘Doctor’));
Output: false
endsWith can find the last word that ends with the word that I insert to search for. You can see both examples one returns true and another that doesn’t match return false. So, endsWith() return true or false.
5. indexOf()
const paragraph = ‘I am Shohag from Bangladesh’;
const searchTerm = ‘from’;
const result = paragraph.indexOf(searchTerm);
console.log(`searching word position is ${result}`);
Output: searching word position is 12
indexOf something similar like concatAt, I insert from word and it returns me the output position of this word inside the paragraph variable.
6. lastIndexOf()
const paragraph = ‘I am from Bangladesh and I am learning JavaScript’;
const searchTerm = ‘am’;
console.log(`searching word “${searchTerm}” from the end is ${paragraph.lastIndexOf(searchTerm)}`);
Output: searching word “am” from the end is 27
lastIndexOf() return the position of ending index you can say the last indexing position of the searched string.
7. replace()
const p = ‘A tech company can be giant if there is real tech heroes’;
console.log(p.replace(‘tech’, ‘garments’));
Output: A garments company can be giant if there is real tech heroes
So, here we can see the replace() method replaces the first word tech and changed it to garments.
8. slice()
const str = ‘I love JavaScript so much’;
console.log(str.slice(2));
console.log(str.slice(2, 17));
console.log(str.slice(-7));
console.log(str.slice(-4, -2));
Output:
love JavaScript so much
love JavaScript
so much
mu
slice() method actually extracts a section of a string position and returns a new string just read the output you will easily understand. It also can extract words from the last position using minus value.
9. split()
const str = ‘Hey Programming is fun’;
const words = str.split(‘ ‘);
console.log(words[1]);
Output: Programming
It divides a string into substring, we insert 1 and it returns the next word.
10. startsWith()
const str1 = ‘Saturday night plans’;
console.log(str1.startsWith(‘Sat’));
Output: true
startsWith() searched the word and match then return true. If it doesn’t match then return false.
11. substr()
const str = ‘Mozilla’;
console.log(str.substr(1, 2));
Output: oz
12. toLowerCase()
const text = ‘HELLO Developers How Are You.’;
console.log(text.toLowerCase());
Output: hello developers how are you.
toLowerCase just convert all the text to Lower Case text. It helps you to make all the text lower case even you write in Upper case.
12. toUpperCase()
const text = ‘HELLO Developers How Are You.’;
console.log(text.toUpperCase());
Output: HELLO DEVELOPERS HOW ARE YOU.
toUpperCase just convert all the text to Upper Case text. It helps you to make all the text upper case even you write in lower case or mixed.
13. trim()
const greeting = ‘ Hello world! ‘;
console.log(greeting.trim());
Output: Hello world!
trim() method removes whitespace from both ends of a string.