Basic Concept of Javascrpit

Md Rishad Khan
3 min readMay 5, 2021

When anyone first begins using Javascrpit, they are a little unsure of where to begin.So I’m going to tell you about some interesting topics that will help you get started with js.

The most important topics are

  1. Variables
  2. Operators
  3. Objects
  4. Arrays
  5. Functions

Variables

In js, you can declare variables in three ways: let, const, and var. Let and var are somewhat similar in that they both store data whose value can change.However, there are several differences that we discuss in other posts.

Now I’ll show you some examples in the upcoming sections.

for (let myLetVariable = 0; myLetVariable < 5; myLetVariable++) {
// myLetVariable is only visible in here
}

for (var myVarVariable = 0; myVarVariable < 5; myVarVariable++) {
// myVarVariable is visible to the whole function
}

Const variables are those whose values are never changed.I’ve included an example below.

const Pi = 3.14;

Operators

In js, you must perform certain mathematical operations that will assist you in performing conditions, math,comparisons and other tasks.Operators assist you in accomplishing both of these tasks.I’ve included an example below.

x += 5;
x = x + 5;
x-=5;
x=x-5;
x=6;
y=7;
if(y>x){a="true" ;console.log(a)} //true
++,-- increment and decrement
123 == '123'; // true
1 == true; // true
123 === '123'; // false
1 === true; // false

Objects

The object is the most important thing in javascript.There are two methods for creating new objects.

var obj = new Object();
var obj = {};

Arrays

JavaScript arrays are also a specific object category. They have one ‘length’ magic property. There is always one higher index than the highest.

var a = new Array();
var a = ['dog', 'cat', 'hen'];
a.length; // 3

It is pretty much easier to store data and call a loop for a length of array.

Functions

The most important thing about any programming language is function.It is a fundamental principle of a programming language.I’ve included an example below.

function add(x, y) {
var total = x + y;
return total;
}

There are numerous imports in js, but you must first study them.However, I will demonstrate a pre-built function that is importable in JS and provide some examples of it.

JavaScript String :

charAt, concat, includes, endsWith, indexOf, lastIndexOf, replace, slice, split, startsWith, substr, toLowercase, toUppercase, trim, trimStart, trimEnd

Javascript Number :

Abs, ceil, floor, min, max, random, round, sqrt

Javascript array:

concat, every, filter, find, findIndex, forEach, indexOf, join, map, lastaIndexOf, pop, push, reduce, reverse, shift, slice, sort, splice, unshift,

startsWith() and endsWith :

Both are similar,one begins at the beginning, the other begins at the end.Essentially, both of these are find string from all strings. I’ve included an example below thats will help you understand.

const str1 = ‘Saturday night plans’;

console.log(str1.startsWith(‘Sat’));
// expected output: true

const str1 = ‘Cats are the best!’;

console.log(str1.endsWith(‘best’, 17));
// expected output: true

concat

Basically, it helps in the addition of new string and the development of new ones.

const str1 = ‘Hello’;
const str2 = ‘World’;

str1.concat( “ ”,str2);

substr

It helps in the cutting of string and the providing of a part.

const str1 = “hello”

str1.substr(1,2);

//output will be “el”

trim, trimStart, trimEnd

trim helps in the exclusion of white space from both sides of the string ,trimstart remove from start and trimEnd remove from end.

const str1 = “ hello “;

str1.trim();

//output “hello”

--

--

Md Rishad Khan
0 Followers

To share my knowledge what i learn from everywhere