JavaScript tutorial)
By: Rizvy Ahamed
Tags: Math, Maps, Splice, JavaScript, Array

JavaScript tutorial

JavaScript is a cross-platform, object-oriented language used to interact with web pages. There are also more advanced JavaScript versions such as Node.js, which allow you to add more functionality to a website rather than simply downloading files. Within the host environment, JavaScript can be linked to its native objects to provide system control over them.

JavaScript contains a standard library of objects, such as Array, Date, and Math, as well as a basic set of language objects such as operators, control structures, and statements. Core JavaScript can be expanded for a variety of purposes by adding additional features; For example:

JavaScript next to the client extends the base language by providing objects to control the browser and the Document Object Model (DOM). For example, client side extensions allow the app to place objects in HTML form and respond to user events such as mouse click, form loading, and page navigation.

JavaScript next to the server extends the base language by providing resources related to JavaScript usage on the server. For example, the server side extensions allow the app to communicate with the database, provide continuous information from one request to another application, or create file fraud on the server.

Details of some JavaScript String, Number, Math, array:

charAt:

charAt () method returns a character in a specified index.

Example:

<html>

<head>

<title> JavaScript String charAt () Method </title>

</head>

<body>

<script type = “text / javascript”>

var str = new String (“This is a string”);

document.writeln (“str.charAt (0) states:” + str.charAt (0));

document.writeln (“<br /> str.charAt (5) states:” + str.charAt (5));

</script>

</body>

</html>

Release: str.charAt (5) by: i

2. concat:

The concat () method is used to combine two or more formats. This method does not change existing settings, but instead returns a new list.

Example: const array1 = [‘a’, ‘b’, ‘c’];

const array2 = [‘d’, ‘e’, ‘f’];

const array3 = array1.concat(array2);

console.log(array3);

Release:> Array [“a”, “b”, “c”, “d”, “e”, “f”]

3. includes:

The includes () method determines whether an array inserts a value into its input, returns true or false as appropriate.

Example: const array1 = [1, 2, 3];

console.log(array1.includes(2));

Release: > true

4. endsWith:

The endsWith () method determines whether a thread ends with a string of threads, returns true or false as it should be.

Example: const str2 = ‘Is this a question’;

console.log(str2.endsWith(‘?’));

Release: > false

5. indexOf:

This method returns an index within the String call item for the first occurrence of a specified value, starting a search from Index or -1 if the value is not found.

Example: const beasts = [‘book’, ‘table’, ‘camel’, ‘knock’, ‘ball’];

console.log(beasts.indexOf(‘table’));

Release: > 1

6. trim:

String.prototype.trim () returns a new thread overrun by white characters from the beginning and end of the series:

Example: let str = ‘ JS trim ‘; let result = str.trim(); console.log(result);

Return: “JS trim”

7. isNaN:

The No.NaN () method determines whether a transferred value is NaN and that its type is a Number. It is the most powerful original version, the global NaNaN ().

Example: function milliseconds(x) {

if (isNaN(x)) {

return ‘Not a Number!’;

}

return x * 1000;

}

console.log(milliseconds(‘100F’));

Return:> “Not a Number!”

8. parseFloat:

The parseFloat () function is used to receive a string and convert it into a floating point number. If the string does not have a numerical value or if the first character of the string is not a number then returns NaN i.e., not a number. It actually returns the number of floating point separated by the point where it reaches a non-Number character.

Example: <script>

var v2 = parseFloat(“2.15”);

document.write(‘Using parseFloat(“2.15”) = ‘

+ v2 + “<br>”);

</script>

Return: Using parseFloat(“2.15”) = 2.15

9. floor:

The Math.floor () function returns the largest value less than or equal to the given number.

Example: console.log(Math.floor(5.95));

Return: > 5

10. splice:

The splice () method alters the content of the same members by removing or replacing existing items and / or replacing new items.

Example: const months = [‘Jan’, ‘March’, ‘April’, ‘June’];

months.splice(4, 1, ‘May’);

console.log(months);

Return: > Array [“Jan”, “Feb”, “March”, “April”, “May”]