Category: Vanilla Javascript

Added: 14th of October 2018

Viewed: 2,981 times

Using document write() in javascript.

If your going to use jquery, or some of the new javascript frameworks and never programmed with javascript before, it's a good idea to learn the basics first, or what they call today Vanilla Javascript.

Over the years I never spent enough time learning to programme in Javascript, and probably like a lot of other users found code online and modified it to fit my needs. That always left me feeling annoyed as it didn't give me a proper understand of the how the script worked, and if I wanted to take the script further I couldn't do it.

I have set myself a challenge to learn some Javascript. I will be adding some examples with explanations for my own reference on the site, and hope that it will come in useful to other users wishing to learn Javascript.

Where to start
One thing I love about Javascript is the ability to write scripts using just a plain text editor, and test it locally in your web browser without the need to upload it to a server, like you would with server side languages such as .php.

Creating a simple javascript is simple, which brings me to the first example, using the document.write() command to out a simple message to your screen.

Example 1: Using document.write() command in Javascript
Create a new .html document on your desktop, and rename the file example1.html

Open the document in your text editor and copy and paste the following code.

document.write("My Computer Tips");

Save the document and open it in your webbrowser. My Computer Tips will be printed to the screen.