This website includes Education Information like a programming language, job interview question, general knowledge.mathematics

Education log

PageNavi Results No.

Ads

Saturday, August 6, 2022

Assigning JavaScript Values in javascript

 Assigning JavaScript Values in javascript


How do you assign a value to a variable in JavaScript?

You can assign a value to a variable using the = operator when you declare it or after the declaration and before accessing it. In the above example, the msg variable is declared first and then assigned a string value in the next statement.


Example of  Assigning JavaScript Values in javascript

<!DOCTYPE html>

<html>

<body>


<h2>Assigning JavaScript Values</h2>


<p>In JavaScript the = operator is used to assign values to variables.</p>


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


<script>

let x, y;

x = 5;

y = 6;

document.getElementById("demo").innerHTML = x + y;

</script>


</body>

</html>


No comments:

Post a Comment