Let and Const Variable tutorial in Advance JavaScript

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Let Const Variable tutorial Advance JavaScript</title>
    <link rel="stylesheet" href="">
</head>

<body>
    <script>
        //var
        var a = "Hello<br>";
        var a = "World<br>";    //We can redeclare variable value with "var"
        a = "How are you ?<br>";    //We can reassign variable value with "var"
        document.write(a);

        //The Scope of variable with "var" is Globally
        if (1 == 1) {
            var b = "Hello var brother<br>";
        }
        document.write(b);

        for (var c = 1; c <= 5; c++) {
            document.write(c + "<br>");
        }
        document.write(c + "<br><br>");

        //let
        let a2 = "Hello<br>";
        // let a2 = "World<br>";    //We can not redeclare variable value with "let"
        a2 = "How are you ?<br>";   //We can reassign variable value with "let"
        document.write(a2);

        // The Scope of variable with "let" is Block Scope
        if (1 == 1) {
            let b2 = "Hello let brother<br><br>";
            document.write(b2);
        }
        document.write(b2);

        // for(let c2=11;c2<=15;c2++) {
        //     document.write(c2 + "<br>");
        // }
        // document.write(c2);

        //const
        const a3 = "Hello<br><br>";
        // const a3 = "World<br>";  //We can not redeclare variable value with "const"
        // a3 = "How are you ?<br><br>";    //We can not reassign variable value with "const"
        document.write(a3);

        if (1 == 1) {
            const b3 = "Hello const brother<br><br>";
            document.write(b3);
        }
        document.write(b3);

        for (const c3 = 21; c3 <= 25; c3++) {
            document.write(c3 + "<br>");
        }
        document.write(c3);
    </script>
</body>

</html>







Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript