JavaScript debugger and var Statement

Learn JavaScript debugger and var Statement



Var Statement

Description
Various announcements in JavaScript, wherever they are, are processed before any code is executed. This work is called hoisting,
Javascript has a variable radius declared with Var. That is the current execution reference, which is either an attached task in JavaScript, or, for any function, declared outside the global variable. If JavaScript Variables are declared by you again, its value will not be reduced.


To create a variable in javascript, a variable is called "declaring".
var carName;

After this, we have to use the equal sign to assign the value to the variable.
carName = "Volvo";

When you are declaring it, at that time you can also assign the value of the variable.
var carName = "Volvo";

Syntax
var varname = value;



var hoisting
Before executing any code in javascript, variable announcements are processed in it, and declaring a variable anywhere in the code is equal to declaring on top. In Javascript it also means that a variable can be used before declaring it. This type of behavior is called "hoisting" in javascript.


bla = 2;
var bla;
// ...
// is implicitly understood as:
var bla;
bla = 2;


Examples

1.Example
In this example two variables were created. It assigns the number 5 to the x, and the number 6 is given by y. Then the result of x + y is displayed. As you can see below:


<!DOCTYPE html>
<html>
<body>
<p>display the result of x + y:</p>
<button onclick="myFunction()">Try it</button>
<p id="web"></p>
<script>
function myFunction() {
    var x = 5;
    var y = 6;
    document.getElementById("web").innerHTML = x + y;
}
</script>
</body>
</html>


2.Example
You can declare a variety of variables in any one of the statements.
In it you have to start the narration with Var. And the comma is separated by commas.


<!DOCTYPE html>
<html>
<body>
<p>declare many variables in one statement:</p>
<button onclick="myFunction()">Try it</button>
<p id="web"></p>
<script>
function myFunction() {
    var lastName = "Doe",
    age = 30,
    job = "carpenter";

    document.getElementById("web").innerHTML = "Name: " + lastName  + ". Age: " + age + ". Work: " + job;
}
</script>
</body>
</html>



3.Example
In JavaScript, using the variable with the loop:


<!DOCTYPE html>
<html>
<body>
<p>Click the button .</p>
<button onclick="myFunction()">Try it</button>
<p id="web"></p>
<script>
function myFunction() {
    var text = "";
    var i;
    for (i = 0; i < 5; i++) {
        text += "The number is " + i + "<br>";
    }
    document.getElementById("web").innerHTML = text;
}
</script>
</body>
</html>



JavaScript debugger and var Statement

JavaScript debugger Statement

Description
In JavaScript, the Debugger Statement gives you permission to observe all kinds of steps. In this you also find out, what kind of problems are there and what kind of small errors are there in the program they have written.

You also have addresses by modifying the states in JavaScript that are addresses by helping you locate the bug. The debugger statement in JavaScript is not only useful for finding bugs, but you can learn how to execute the statement in Javascript.

You should know that the debugger statement will not be effective until the developer panel opens in the browser.


Syntax
debugger;


Example-


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id="web"></p>
<p>In addition to running the debugger in javascript, the code inside the script element will stop executing it before executing the third line.</p>
<script>
var x = 15 * 5;
debugger;
document.getElementById("web").innerHTML = x;
</script>
</body>
</html>

Learn JavaScript debugger and var Statement-Var Statement Various announcements in JavaScript, wherever they are, are processed before any code is executed. This work is called hoisting,Javascript has a variable radius declared with Var. That is the current execution reference, which is either an attached task in JavaScript, or, for any function, declared outside the global variable.debugger Statement- In JavaScript, the Debugger Statement gives you permission to observe all kinds of steps. In this you also find out, what kind of problems are there and what kind of small errors are there in the program they have written.

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget