DEV Community

AravindhBalakrishnan
AravindhBalakrishnan

Posted on

Let's start JavaSciprt.

Java script is a scripting language where we can add interactive elements to a static webpage. Java script is a dynamically typed language which is interpreted line by line not like compiled one.
JS is formally known as Mocha then live script which after java's popularity changed its live script name into javascript.

JS can be written inside a HTML page within <script> tag.
Let see a small JS program to print

Hello World

<script> 
console.log("Hello, World!");
</script>
Enter fullscreen mode Exit fullscreen mode

Now we can write smaller arithmetic functions like addition, subtraction, multiplication, division using variable.

Like all programming languages JS also uses variable to perform operations on the values which is stores in identifiers which we can call as variable.

We can declare a variable and initialise a value to that variable using let keyword. let a = 20 is used to declare and initialise variable an and assign a value of 20 to a. We can also use var and const to declare a variable. But let is used rather than var since var allows to redeclare the same variable which leads into changing of actual value at any part of the program where as let will not allow users to create same variable again in any part of the program which is more safer option.

<script>
let a = 20;
let b = 30;
console.log(a+b);
</script>
Enter fullscreen mode Exit fullscreen mode

Similarly we can perform subtraction, division, multiplication, modulo function.

<script> 
let a = 20;
let b = 10;
console.log(a-b);

let a = 20;
let b = 10;
console.log(a*b);

let a = 20;
let b = 10;
console.log(a/b);

let a = 20;
let b = 10;
console.log(a % b);
</script>
Enter fullscreen mode Exit fullscreen mode

const keyword is used to create a variable which need not be changed at any part of the program lets us say value of pi which is 3.142 which can be declared as const variable.

<script> 
const pi =3.142 
let radius = 3; 
let area = pi*radius*radius; 
console.log(area); 
</script>
Enter fullscreen mode Exit fullscreen mode

In this above program we can change the value of radius but now the value of pi when we try to give new value for pi it will throw a error and we cannot assign new value to pi

Let's see about the data types in JS. Like other programming languages we have datatypes Number , string , BigInt, Boolean are commonly used datatype.

Number is used to represent numeric value. But when number becomes large than a safe integer value we need to use BigInt. Also we can store floating value and double value in_ Number_ datatype.

eg.

let a = 123;
let b = 2.567; 
let c= 1234567890; 

Enter fullscreen mode Exit fullscreen mode

String is used to represent series of characters and text which can be represented within " "

eg.

let a  = "ABC is the first 3 alphabet of English"; 
let name = "Aravindh Balakrishnan "
let address = "Chennai, Tamil Nadu, "
let mobileNumber = " 98900000000"

Enter fullscreen mode Exit fullscreen mode

Boolean is used to represent true or false

let x = true;
let y = false;

Enter fullscreen mode Exit fullscreen mode

There are few more datatype is there which is Undefined , Null , Symbol , Object

Undefined is used to represent not assigned value but a variable is declared.

Null is used to represent empty value of the variable.

Symbol is used to represent unique value of the variable which doesn't allow other variable to use the same value.

Object is a datatype which is used to represent key:value pair of the data.

Top comments (0)