Master JavaScript Programming From Scratch

Clear, interactive, and structured JavaScript lessons designed for absolute beginners.

Input and Output

Learn how JavaScript receives values and displays information while running a program.

What are Input and Output?

Input means providing data to a program. Output means displaying the result produced by the program.

In browser-based JavaScript, input can come from HTML forms, buttons, text fields, and browser APIs. Output can be displayed on the page or in the browser console.

JavaScript data flow and values

JavaScript works with values supplied by the application and produces results from those values.

Common Input and Output Methods

Input

User input commonly comes from HTML forms, text boxes, buttons, and browser APIs.

Output

JavaScript can display information using console.log() or by updating HTML content.

Simple Input and Output Flow

Data Flow
Input
→
JavaScript
→
Processing
→
Output

Console Output

The console.log() method displays values in the browser console. It is commonly used while learning and debugging JavaScript.

Example 1: Displaying Output

const institute = "CIIT Training Institute";
const course = "JavaScript";

console.log("Institute:", institute);
console.log("Course:", course);
console.log("Learning JavaScript ❤️🧑‍🎓.....!");

Output

Institute: CIIT Training Institute
Course: JavaScript
Learning JavaScript ❤️🧑‍🎓.....!

Using Input Values

In a real web application, a value can come from an input field. Here we use a variable to represent the value received by the program.

Example 2: Input Value and Output

const studentName = "Shivani";
const marks = 88;

console.log("Student Name:", studentName);
console.log("Marks:", marks);

console.log(studentName + " is learning JavaScript.");

Output

Student Name: Shivani
Marks: 88
Shivani is learning JavaScript.

Input from an HTML Form

In browser applications, JavaScript can read values entered into HTML input elements and then process those values.

Example

A student can enter a name in a text box. JavaScript can read that value and display a greeting on the page.

Important Point

Input is the data received by a program. Output is the information produced by the program. In browser applications, JavaScript often connects HTML input elements with JavaScript logic.

Summary

Input provides data to a JavaScript program, while output displays the result. JavaScript commonly uses console.log() for console output and can also read values from HTML form elements.