Here's a simple JavaScript program that demonstrates how to declare and use variables:
This program uses the var
keyword to declare variables x
, y
and z
. The variables are then assigned values using the assignment operator =
. The variable x
is assigned the value of 5, the variable y
is assigned the value of 10, and the variable z
is assigned the value of the sum of x
and y
(5 + 10 = 15).
The document.write()
method is used to display the value of the variable z
on the screen. The string "The value of z is: " is concatenated with the value of z
using the +
operator.
This program demonstrates how to declare variables in JavaScript, assign values to them, perform mathematical operations with them and how to display the result on the screen.
You can use any text editor that supports HTML and JavaScript like Visual Studio Code, Sublime Text, Atom or any other text editor that supports javascript.
No comments:
Post a Comment