Menu

Basic JavaScript: Variables and Functions

Basic JavaScript: Variables and Functions

JavaScript makes a page respond to things instead of just sitting there. Like CSS, it deserves its own full handbook, but here are the basics you need.

A variable stores information so you can use it later. In modern JavaScript, you create one using let or const. A function is a reusable block of code that runs when you call it.

let visitorName = "friend";


function greetVisitor() {

  console.log("Welcome, " + visitorName + "!");

}


greetVisitor();

Explanation:

  • visitorName is a variable holding a piece of text.
  • greetVisitor is a function that, when invoked (called), prints a welcome message using that variable. The last line actually runs the function. Without calling it, the function would just sit there doing nothing.

HTML Tutorial (From Basics to Implementation)

AP

Abhishek Pati





Get in Touch For Details