Basics of JavaScript

Aporbo Ghosh
3 min readMay 5, 2021

--

JavaScript is a object oriented programming with object prototype. It is a dynamic language with types and operators with methods. JavaScript program is based on values and this values are depend on different type. There are some types of values. It can be number/ string/ Boolean and functional. It also be object and symbol. It has array which is one type of special object. Now let’s talk about numbers and functions.

Numbers:

The JavaScript type number is double precision 64 bit binary format. We can call it integer but if you know that all integers are number but all number is not integer then you should be careful. For example, if you divided 5 by 2 it will be 2.5 which is a float. There is some functions to convert a any string to integer. In IsINT method If the target value is an integer, return true, otherwise return false. If the value is NaN or Infinity, return false. The method will also return true for floating point numbers that can be represented as integer. There is also a method of number is IsNAN. The Number.isNaN() method determines whether the passed value is NaN and its type is Number. It is a more robust version of the original, global isNaN().

Function:

Function is a core component of JavaScript. For example if you want solve a basic arithmetical problem in JavaScript, you use a function. For example

Var a=5;

Var b=10

Function add (a+b){

Var sum = a+b;

return sum;

}

While the function declaration above is syntactically a statement, functions can also be created by a function expression.

So let’s talk about function expression.

Function expression:

The function keyword can be used to define a function inside an expression.

You can also define functions using the Function constructor and a function declaration.A function expression is very similar to and has almost the same syntax as a function declaration. The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions.

String:

To manipulate sequence of characters string type is used in JavaScript. In short form strings are used or useful to hold text format data.Strings can be created as primitives, from string literals, or as objects, using the String() constructor.There are two ways to access an individual character in a string. The first is the charAt() method.Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character—in a string called stringName—is stringName.length - 1. If the index you supply is out of this range, JavaScript returns an empty string. In so many methods there has a method named trimstart.The trimStart() method removes whitespace from the beginning of a string. trimLeft() is an alias of this method.

CharAt:

The String object’s charAt() method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string. An integer between 0 and str.length - 1. If the index cannot be converted to the integer or no index is provided, the default is 0, so the first character of str is returned.

IndexOf:

The indexOf()method is used to search a specified value in string, and returns a first position within a string. It is case-sensitive method.
Syntax: indexOf(searchValue)
Example: const str = ‘beauty of nature’
console.log(“first position is :”+str.indexOf(‘of’)
Result is: ’first position is :7

parseFloat:

parseFloat method parses a sting argument and covert it to floating point number. It returns floating point number from given sting value.
Syntax: Number.parseFloat(stringValue)
Example: let stringValue=”50.34Value”
Number.parseFloat(stringValue);
Result is :50.34

Array:

Array is a common data type in JavaScript. While writing a JavaScript program we often have to work with arrays. Today I will talk about 10 common JavaScript array methods which every JavaScript programmer must know. Let’s talk about concat, filter.

Concat:

concat() method is used merge to or more arrays. This method merges passed arrays with current array and returns a new array. This method does not change the current array.

Filter:

filter() method is used to get the elements of an array satisfying a test function. Returns a new array with the elements that pass the test function. Returns an empty array if no element pass the test function.

--

--