JavaScript Tutorials


» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls


» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement


» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop


» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions


» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays


» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword


» Introduction to AJAX


» Introduction to JSON


» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)


» Math Object

» Math Methods


» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events


» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript


» JavaScript Calculator

.. » JavaScript » Introduction » JavaScript Output
Share Tweet WhatsApp

JavaScript Output

To easily output data or text in JavaScript, you can make use of some predefined JavaScript functions. JavaScript alert() The JavaScript alert() is a function you can simply use in outputting data (text only) to a user. It works more like a pop up message that display whatever text given to it via its parameter and gives an option to the user to close it (the alert). Example
alert("Welcome to my website.");


For most of the examples in this tutorial, we shall be using the JavaScript alert function to output data. JavaScript document.write() The write() is a method of the document object, which is an object of a webpage. With this method, you can output both text and HTML on any part of your webpage.
<h1>Hello World</h1>
document.write("<h2>How are you today?</h2>");


  • Do not use the document.write() after a webpage has fully loaded by maybe calling a function where it is being used in outputting text/HTML. It will erase the rest of your webpage contents. See below,
    <h1>Hello World</h1>
    <button onclick='myFunc()'>Click Me</button>
    function myFunc(){
    document.write("How are you today?");


    Notice how the previous contents were erased.
You will learn about the document object in subsequent tutorials. JavaScript console.log() The log() is a method of the console object, which is an object of a browser's console. With this method, we can log messages/texts on a browser's console.
console.log("Process running...");
The console.log() should only be use for development and testing purposes as such messages are not directly outputted to the user rather till they open their browser's console and that will be if they even know a message is there or something of such even exists. Usually, when your JavaScript programs refuses to execute as a result of some errors, those errors are sent/displayed in the browser's console. SUMMARY
  1. To easily output texts in JavaScript, we can make use of the predefined alert() function.
  2. The data should be text only. HTML can not be interpreted on the alert pop up.
  3. If you have HTML markups in a text to be outputted by the alert, the markups will be display just the way they are. No interpretations.
  4. document.write() is yet another easy way to write both text and HTML contents on a webpage when it is loading.
  5. The document.write() should not be use after a webpage have fully loaded. It will erase all other contents on a webpage.
  6. Yet again, there is the console.log() to log messages on a browser's console.
Take a short quiz on JavaScript Output.
Ask a question or tell us if JavaScript Output is easy or not.

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.

StackBeginner 2021 © Joseph Omamode