Start a new journey with JavaScript
Okay!
First of all Congratulation to you for taking a great initiative and that is learn about something. so congratulation again.
Let's began with a short introduction to javascript.
In 1995, JavaScript was created by Brendan Eich. At this time he was an engineer at Netscape. JavaScript was first released with Netscape 2 early in 1996. It was originally going to be called LiveScript, but it was renamed JavaScript which is a marketing decision that attempted to capitalize on the popularity of Sun Microsystem’s Java language — As if two having very little in common. This has been a make a wellspring of disarray from that point forward.
JavaScript syntax is based on C and Java languages. Let’s start off by looking at the building blocks of any language: the types. JavaScript programs manipulate values, and those values all belong to a type. JavaScript’s types are:
10most important topic will be given below for a better idea about javascript
Variables
There are three types of variable in javascript : let
, const
, or var
.
let
is used in a block-level variable :
let a;
let name = 'Dihan'; //Dihan
// myFunction is *not* visible out here
for (let myFunction = 0; myFunction < 5; myFunction++) {
// myFunctionis only visible in here
}
// myFunctionis *not* visible out here
const
allows you to declare in once in the entire code and it never changes.
const a = 'Dihan'; // variable a is set
a = 'ábir'; // will throw an error because you cannot change a constant variable.
Operators
JavaScript’s numeric operators are +
, -
, *
, /
and %.
Math
There is also a built-in object that is called Math
that provide us some advanced mathematical functions which are given below:
Math.sin(3.5);
var circumference = 2 * Math.PI * r;---console.log(3 / 2); // 1.5, not 1
console.log(Math.floor(3 / 2)); // 1console.log(Math.ceil(3 / 2)); // 2
parseInt()
If you need to convert a string to an integer then we can use the built-in function calledparseInt()
. This takes the base for the conversion as an optional second argument( this is mandatory to provide always):
parseInt('123', 10); // 123
parseInt('010', 10); // 10parseInt('010'); // 8
parseInt('0x10'); // 16
splice()
This ‘’splice() ‘’ method takes three-parameter, first for all targeted the index number, second for how many items you want to delete/update or replace and the third parameter is what you want to insert.
let names = [‘dihan’, ‘abir’, ‘murad’];
let name = names.splice(2,0, ‘robin’, ‘jalal’ );
console.log(name);
let names = ['dihan', 'abir', 'murad'];
let name = names.splice(2,0, 'robin', 'jalal' );
console.log(name);
JS String : charAt( )
chatAt function takes an integer number as a parameter which is called “index”and return a new char corresponding to the “index” value.
const text = ‘this is chat’;
const index = 3;
console.log(text.charAt(index));// output : i
Map
Map is a collection of keyed data items, just like an Object
. But the main difference is that Map
allows keys of any type.
Methods and properties are:
new Map()
– creates the map.map.set(key, value)
– stores the value by the key.map.get(key)
– returns the value by the key,undefined
ifkey
doesn’t exist in map.map.has(key)
– returnstrue
if thekey
exists,false
otherwise.map.delete(key)
– removes the value by the key.map.clear()
– removes everything from the map.map.size
– returns the current element count.
let map = new Map();
map.set('1', 'str1'); // a string key
map.set(1, 'num1'); // a numeric key
map.set(true, 'bool1'); // a boolean key
// remember the regular Object? it would convert keys to string // Map keeps the type, so these two are different:
alert( map.get(1) ); // 'num1'
alert( map.get('1') ); // 'str1'
alert( map.size ); // 3
Set
A Set
is known as a special type of collection where each value may occur only once at a time.
Its main methods are:
new Set(iterable)
set.add(value)
set.delete(value)
set.has(value)
set.clear()
set.size
Iteration over Set
let set = new Set(["oranges", "apples", "bananas"]);
for (let value of set) alert(value); // the same with forEach:
set.forEach((value, valueAgain, set) => { alert(value); });
Arrays
Array in JavaScript is really an extraordinary kind of article. They work a lot like customary articles. However, they have one common property called ‘length’. This is consistently one more than the most elevated record in the exhibit.
var a = new Array();
a[0] = 'Rakib';
a[1] = 'Nahid';
a[2] = 'Nayeem'
a[3] = 'Nayeem';
a.length; // 4