JavaScript

Tuesday April 8, 2025
updated: April 10, 2002

 
Home
Getting Started
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Resources
Credits

 

 


Lesson 3 Example: Variables

CODE

RESULT

<script>
<!-- hide code from old browsers
var adjective="Exhilarating"
document.open()
document.write("This is "+ adjective +"!")
document.close()
// end hiding code -->
</script>
This is Exhilarating!
    • First the variable "adjective" is assigned the value of "Exhilarating"
    • Next the document is opened and written to.
    • The write statement outputs the variable adjective.
    • The variable adjective is not in quotes because, we want the value of the variable to be displayed, which is Exhilarating (not the actual text "adjective"). Notice there is a space between the word is and the quotation mark ".
    • the plus sign, + is an operator which adds the variable to the text to be written to the document.
    • Finally, the document is closed so the browser stops trying to load it
back button
next button

© 2002 Tracy Johnson