Declare many variables in one statement. - Javascript Data Type

Javascript examples for Data Type:var

Introduction

Start the statement with var and separate the variables by comma:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//  ww w  .  j  av a  2s  . co  m
    var lastName = "Bond",
    age = 30,
    job = "carpenter";

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

</body>
</html>

Related Tutorials