Simple JavaScript Example: Easy Code Tutorials

Bobby Jul 13, 2026

Welcome to the fascinating world of JavaScript! If you're new to this programming language, you might be wondering where to start. Don't worry, we'll kick things off with simple and engaging examples that will have you coding in no time. Let's dive in!

a calculator is shown with the numbers below it
a calculator is shown with the numbers below it

JavaScript is the backbone of modern web development, powering everything from interactive websites to complex web applications. It's high time you explore its vast potential. Let's begin with some fundamental concepts and work our way up.

Java script string method
Java script string method

Getting Started with JavaScript

Before we dive into the fancy stuff, we need to set up our environment. The easiest way to start is by opening your web browser and using the developer tools. For this example, let's use Google Chrome.

HTML input types
HTML input types

Press F12 to open the developer tools. Go to the 'Console' tab - this is where JavaScript magic happens. Here, you can type and run JavaScript code instantly. It's like having a personal JavaScript assistant!

Hello, World! - Your First Program

Create Lists From JSON Data in Javascript (Simple Examples)
Create Lists From JSON Data in Javascript (Simple Examples)

No coding journey is complete without the classic "Hello, World!" program. Let's make your JavaScript debut unforgettable.

Type the following in the console and hit Enter:

console.log("Hello, World!")

Congratulations! You've just run your first JavaScript code. You should see "Hello, World!" printed in the console. Isn't that exhilarating?

javascript cheetsheet
javascript cheetsheet

Variables - Storing Data

Variables are likeReally useful boxes where you can store data. Let's create a variable named 'message'.

Type this in the console:

JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)

let message = "Hello, World!";

Now, you can retrieve the value stored in the 'message' variable by simply entering 'message' in the console. It's as easy as that!

Basic Data Types

JavaScript Basics | Chapter 1 📖 | Part 2
JavaScript Basics | Chapter 1 📖 | Part 2
Using switch Statements in JavaScript
Using switch Statements in JavaScript
Javascript window.confirm() method | Javascript tutorial
Javascript window.confirm() method | Javascript tutorial
JavaScript Tips to Change Border Radius & Background Color
JavaScript Tips to Change Border Radius & Background Color
JavaScript Basics | Chapter 1 📖 | Part 1
JavaScript Basics | Chapter 1 📖 | Part 1
Update HTML in DOM: Change Text Live
Update HTML in DOM: Change Text Live
Very Simple Accordion In Pure Javascript
Very Simple Accordion In Pure Javascript
"Master JavaScript's Slice Method �: Easy Array & String Slicing Tips! 🚀 #CodingTips #WebDev"
"Master JavaScript's Slice Method �: Easy Array & String Slicing Tips! 🚀 #CodingTips #WebDev"
Click Events in JavaScript
Click Events in JavaScript
JavaScript Basics for Beginners | Learn JS Step by Step
JavaScript Basics for Beginners | Learn JS Step by Step
JavaScript Template Literals: Write Cleaner & Dynamic Strings 📝
JavaScript Template Literals: Write Cleaner & Dynamic Strings 📝
A Simple Guide to ES6 Iterators in JavaScript with Examples
A Simple Guide to ES6 Iterators in JavaScript with Examples
Essential JavaScript String Methods for Beginners
Essential JavaScript String Methods for Beginners
JavaScript template literals
JavaScript template literals
Toggle Fullscreen Mode in Javascript
Toggle Fullscreen Mode in Javascript
Read Files In Javascript
Read Files In Javascript
the instructions for how to use an object in visual language, including text and numbers
the instructions for how to use an object in visual language, including text and numbers
Javascript Flashcards Web App
Javascript Flashcards Web App
JavaScript Operators | Simply explained 🚀
JavaScript Operators | Simply explained 🚀
Javascript Window.print()
Javascript Window.print()

Before we delve deeper into JavaScript's capabilities, let's explore its data types. Data types tell you what kind of data an operation will return and what operations are possible on it.

Four of the most common data types are Numbers, Strings, Booleans, and Objects (including Arrays). Let's explore each of these with examples.

Numbers - Math Operations

Numbers are used to perform mathematical operations. They can be whole (integers) or have a fractional part (floats).

Try these simple calculations in the console:

1 + 1 // this will return 2 5 * 6 // this will return 30

Strings - Text Manipulation

Strings are used to store and manipulate text. They can be enclosed in single (''), double (""), or even back ticks (`) - it's all the same!

Let's create a string for a greeting and then change its case:

let greeting = "hello, world!"; greeting.toUpperCase() // this will return "HELLO, WORLD!" greeting.toLowerCase() // this will return "hello, world!"

Booleans - Binary Values

Booleans can take one of two values: true or false. They're essential in JavaScript for making decisions - a topic we'll delve into later.

Here's a simple example of a Boolean in action:

let isJavaScriptFun = true;

To check a value's truthiness, use the console.log() function:

console.log(isJavaScriptFun)

It will print 'true', as expected!

Objects - Storing Multiple Values

Objects in JavaScript are used to store and organize data. They're like a big box of drawers where you can keep related items together.

Try creating an object to store some details about yourself:

let userProfile = {name: "John", age: 30, isStudent: false};

You can access the values inside the object like this:

console.log(userProfile.name) // this will return "John"

Objects can also be used to create more complex data structures, like arrays (another type of object).

Amazing, isn't it? You've barely scratched the surface of JavaScript, and you're already handling numbers, strings, Booleans, and objects. Now that you've got the basics down, the world of JavaScript awaits! The next step could be learning about functions, control structures, or even diving into advanced topics like 'this' and 'prototypes'. The choice is yours! Happy coding!