DEV Community

Guna Ramesh
Guna Ramesh

Posted on

JavaScript Basics

1.What is JavaScript?
JavaScript is a scripting programing language used to make website interactive.
example: click a button -> something happens.
used with
Html for make Content Structue.
Css for to make Design and Style.
JS for to make a Behaviour.

2.what is Interpreter?
Interpreter is a program thats reads and executes a program line by line instead of execute whole program at once.Js also called Interpreter
programming language because its executes a program line by line.

Advantage:     Error shown instantly.
           Execute line by line.
Disadvantage:  Slower than Compiler.
Enter fullscreen mode Exit fullscreen mode

3.What is Variable In JavaScript and How to use?
Variable are declared a keyword like var , let and const.

example:       var a=10;
           let a=20;
           let name="gunalan";
           const a=true;
Enter fullscreen mode Exit fullscreen mode

4.What is the Difference between Var Let and Const?
In JavaScript, variables are declared using three keywords: var, let, and const.
Each has different behavior in terms of scope, reusability, and mutability.

1.var is the oldest way to declare variables in JavaScript.
    var name = "Guna";
Features:
        Function-scoped (not block-scoped)
        Can be allow redeclared
        Can be reinitialized
        Gets hoisted (moved to top internally)

        var x = 10;
        var x = 20; //its allowed
var is not recommended in modern development due to unexpected behavior.
example:
        {
            var a=10;
            console.log(a);
        }
        output:10
        ---------------------
        {
            var a=10;
        }
            console.log(a);
        output:10


2.let is used for variables that may change.But cant to redeclare. And its only access inside the block. Because its block-scope.
    let a=10;
    let a=15; //cant allow redeclare 
        a=15;//allow to reinitial.
Features:
        Block-scoped ({ })
        Can be updated
        Cannot be redeclared in the same scope  
example:
        {
            let a=10;
            console.log(a);
        }
        output:10
        ---------------------
        {
            let a=10;
        }
            console.log(a);
        output:a is not defined

3.const is used for values that should not change.
    const age = 23;
Features:
        Block-scoped
        Cannot be updated
        Cannot be redeclared
        Must be initialized during declaration
example:
        {
            const a=10
            console.log(a)
        }
        output:10   
        --------------------------
        {
            const a=10
        }
        console.log(a)
        output:a is not defined.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)