4 important part of JavaScript must read for the beginners
If you are a beginner of JavaScript and have a minimum knowledge about programming language, this article is going to more easy and understandable for you. So lets Start.
JavaScript has a little difference from other programming languages. It has no concept of input or output. Basically, JavaScript’s mechanism is designed to run as a scripting language in host environment(browser). Its syntax and structure is inspired from Java and C.
JavaScript is also known as multi-paradigm and dynamic language. It also contain types, operators, built-in objects, methods like other languages.
Now we can start the 10 important parts of JavaScript.
- Variable
In JavaScript, variables are declared as let, const and var.
Firstly, we will talk about ‘let’ variable. It is used as a block-level variable. that means it is accessible from a block. for example:
// here variable i is initialized as let
//i is not visible out herefor (let i = 0; i < 5; i++) {
// i is only visible in here
}
// i is not visible out here
Now lets talk about ‘const’. const have come from constant, which means never change.
const K = 8; // you can not change it
k = 1; // here you got an error because you cannot change a constant variable.
Lastly, ‘var’ is the oldest variable type. basically using var you can access it from everywhere.
// here variable i is initialized as var
//i is visible out herefor (let i = 0; i < 5; i++) {
// i is visible in here
}
// i is visible out here
2. Operator
JavaScript has operators like other language have. +
, -
, *
, /
and %.
there are some operator which uses for comparison<
, >
, <=
and >=.
In JavaScript there is a simple difference. between ==
and ===.
I will explain with an example:
555 == '555'; // true
0 == false; // true555 === '555'; // false
0 == false; // false
3. Strings
Strings in JavaScript are successions of Unicode characters. String is sequences of UTF-16 code units, each unit is represented by a 16-bit number.
There are some built-in method in string like length, charAt, replace, toUpperCase etc. Lets see some example:
'javascript'.length; // 10
'hello'.charAt(0); // "j"
'hello, javascript'.replace('javascript', 'java'); // "hello, java"
'javascript'.toUpperCase(); // "JAVASCRIPT"
4. Number
Numbers in JavaScript follows “Double-precision 64-bit format IEEE 754 values”.
0.1 + 0.2 == 0.30000000000000004;
There are some build in function that give us some interesting output like sin, PI, parseInt, parseFloat, isNaN. Lets have a look some example:
Math.sin(3.5);
parseInt('123', 10); // 123
parseInt('010', 10); // 10
isNaN(NaN); // true
here sin function gives us the value of sin and parseInt function makes a string to binary, octal , decimal or any number system.
these are the important things which are must for the beginners.