Saturday, 10 July 2021

JavaScript tutorial #3 | Variable , datatypes , Complete information with rules @echocoding | soham


third.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>variable</title>
</head>
<body>
    <script>
        var person  = "Kunal";
        var person;
        person = "Rohit";//string

        var number = 1;//int
        var floatdatatype = 1.02 //float
        var number = "1";//string
        var _coder = "Programmer";
        var myFirstVariable;
        // multiple variable in single line
        var Programmer = "Rohan",myclass = "12th",website = "xyz.com";
        var Programmer = "Rohan",
        myclass = "12th",
        website = "xyz.com";
    
        // Re-declaration  in variable
        var program = "Javascript is easy to learn";
        console.log(program); 
        program = "HTML is more easy than javaScript";
        console.log(program);
           
    </script>
</body>
</html>

Variables

Imagine programmer has a glass of water So we can say glass is variable and water is value or data . As programmer imagine glass store water in the same way Varibles are also contain different different values.

Data Type

Data type are nothing but the type of data that a values contain.

like Int , float , string ,  boolean , arrays , objects ,  more...

"NO need to declared data type in JavaScript"

Rules in JavaScript to Declared varibles

1 Variables contains letters , underscores , digits and dollars sings.

2. Variables are start with letter , $ sign and _ underscore only.

3. Variables Name are CaseSensitive.

4. Reserved keywords (class , id , function) cannot used in javascript.

One statement and many variables

var programmar = "Rakesh" , class = "12th" , subject = "Maths";

or

var programmar = "Rakesh",

class ="12th",

subject = "Maths";

overriding in JavaScript

var person = "rohit";

person = "Rakesh";

Difference between var , let , const 

var can reassinged values in same block scope or different block of scope , although It can assing values befor declared variables  (hoisting is possible).

let can not reassinged values in same block scope but It can assing values in different block of scope.Hoisting is not possible(In let , variable can not assing values before let declaration).

const can not reassinged values in same block of scope but it can assing values in different block of scope. Hoisting is not possible   (In let , variable can not assing values before let declaration).


Timestapms

Introduction and use of variable 00.01

Datatype 03.05

Rules to  define variable name  05.40

One statement with multiple variables 07.50

Re-declaration of varialbes (Override variables) 09.48






No comments:

By laptop