Creating Variables and Using the JavaScript Alert()

New Post Public Reply Private Reply Replies (0) Message Board
nerd

Creating Variables and Using the JavaScript Alert() Function

Let's create a simple HTML document that we can use to test our variables:

Learn How to Code Part I: Variables and Basic Data Types
(Right click this link and choose to save the document to download a copy of this skeleton HTML file.)

You're going to want to have a better-defined HTML document when you're actually writing code, but for our purposes this will work just fine. Save the code above as a file called myscript.html (or anything you want that ends in .html and doesn't contain spaces or special characters) and open it up in your web browser. You'll see absolutely nothing other than "My Script" in the title bar. We still have more work to do. First, let's declare a variable inside of the script tag:

myVariable = 5;

Here we've just declared a number. Let's look at other variable types we can declare

myNumber = 5;
myString = "Hello world!";
myBoolean = true;

That gives us a number, a string, and a boolean. Now let's take that myString variable and actually do something with it:

myNumber = 5;
myString = "Hello world!";
myBoolean = true;
alert(myString);

You'll notice I've added the line alert(myString); . This calls a built-in JavaScript function (we'll learn more about these later) called alert() which creates a pop-up dialogue box for users to interact with.

What is "Hello world!" all about?

Writing a simple program that says "Hello world!" is generally the first thing every programmer does when they're learning how to code. It's not necessary, but it's sort of a tradition and an initiation into the club.

You never really want to use these in practice because—as any internet user likely knows—alert boxes are very annoying, but they make for a good way to test your code, to make sure it works, while you're writing. The parenthesis following alert allow you to provide alert with data it might need. Not all functions will require that you give it information, but alert needs to know what to alert the user. In this case, we gave it myString, so the user will receive a popup notification that says "Hello world!" Try this with your other variables to get popups with a number and a boolean value.

Why give alert() a variable and and not just give it the contents of the variable? Well, if you said alert("Hello world!") you'd get the same result in this example, but variables are called variables because they vary . The idea is that the contents, or values, of these variables will change as users interact with the programs you write.

Scroll down for more posts ▼

Top 10 Most Recent News Articles

InsCorp's Steady Q3 Climb Mirrors Strategic Focus

Updated Category News Views 46

Riding the Revenue Wave Now we're talking about a bank knowing their business—InsCorp, Inc. recently flaunted a 12% year-on-year revenue bump for 3Q26, a testament to a strategy that's clearly sticking. Still, while those numbers are nice and shiny, the detailed breakdown shows earnings per share (EPS) barely budged from last quarter, coming in at $0.73, just a hair...

Continue Reading
Nanoscope Therapeutics Aims for Eye-Catching Advances

Updated Category News Views 87

Gearing Up for a Boston Showcase Nanoscope's High-Stakes Boston Rendezvous In a move set to grab some serious eyeballs, Nanoscope Therapeutics is geared up to strut their stuff at Advanced Therapies USA 2026 in Boston. Scheduled for November 4–5 at the Hynes Convention Center, the event isn't just another pitstop—it's a billboard for what these guys have cooking. With...

Continue Reading
Kuvings Unveils Hands-Free Juicer for Healthy Living

Updated Category News Views 96

A Fresh Squeeze in the Juice World If you've ever wanted something that makes that morning juice without you running a marathon in your own kitchen, Kuvings might just have the answer with their new AUTO10 SQUARE™ Plus. Announced on October 30, 2026, this isn't just another fancy named gadget—it actually shakes things up with a hands-free design that’s tailored for...

Continue Reading
CMRE Facing Legal Heat Over Wage Allegations

Updated Category News Views 10

Another Day, Another Lawsuit Ah, work. It’s what gets us up in the morning, whether we like it or not. Yet, for many, it can feel more like a dubious hustle when the rewards don't match the effort. Now, CMRE Financial Services, Inc. finds itself under the legal microscope, thanks to a fresh class-action lawsuit filed by the legal eagles at Blumenthal Nordrehaug Bhowmik...

Continue Reading
Lepage Millwork to Acquire Custom Window Maker Fenêtres MQ

Updated Category News Views 64

Big Move in Windows: Lepage Eyes Fenêtres MQ Dust off those old window ledgers, folks, because we've got a shake-up in the custom luxury window game. Lepage Millwork, a family-run titan in the North American fenestration scene, is gearing up to take over Fenêtres MQ from the big shots over at Andersen. We're talking about an ownership shift set to seal the deal by...

Continue Reading
Bybit Unveils Platform Vision at HK FinTech Week

Updated Category News Views 63

Bybit's Strategic Participation at HK FinTech Week Here’s what’s got everyone buzzing: Bybit is stepping onto the big stage at the Hong Kong FinTech Week 2026. We're talking about the crème de la crème of fintech gatherings, where the sharpest minds of the financial world mingle, munch, and strategize under the buzzing neon of Hong Kong. Bybit's involvement is no...

Continue Reading
WHI's Nexus AI Transforms Phone Ordering in Parts Biz

Updated Category News Views 174

Nexus AI: The New Frontline for Part Distributors In a move poised to shake up the auto parts distribution scene, WHI Solutions, a child of eBay, is rolling out a game-changer: the Nexus AI suite designed for the Nexpart platform. Now, tech and tradition blend as AI tackles phone ordering for those early-morning rushes and late-night calls. A Solution for Your Busiest...

Continue Reading
Texas Home Boasts PGA-Caliber Green with Synthetic Turf

Updated Category News Views 40

Swinging for Luxury in Your Backyard Who'd have thought that a chunk of Austin, Texas, could boast a putting green that’s giving any PGA course a run for its money? We’re talking about a family here who decided they’d had enough of scalding summers and winter chills and wanted a taste of that country club glam at home without the upkeep headaches. The Rise of...

Continue Reading
California Housing Affordability Stagnant as Rates Rise

Updated Category News Views 55

Numbers Tell the Story Get this: California's housing market's as sticky as day-old gum on a hot sidewalk. Despite a dip in home prices, affordability just won't budge. The California Association of REALTORS® (C.A.R.) says 19% of households could afford a median-priced home at $894,630, exactly like last quarter and even a year back. Not a flicker of change. Quirky it...

Continue Reading
Endava's Securities Class Action Heats Up Wall Street

Updated Category News Views 13

A Head-Spinning Fall for Endava Endava's recent tumble on the NYSE has investors rubbing their eyes in disbelief. A jaw-dropping 25% slide in share value on September 22, 2026, has everyone scrambling for answers. Looks like some serious skeletons were hiding deep in Endava's closets—management snafus and fuzzy accounting being at the forefront. This debacle has peeled...

Continue Reading

Top 5 Most Recently Viewed Articles

Wells Fargo & Co Short Interest Insights and Impact

Updated Category News Views 207

Understanding the Recent Movement in Wells Fargo & Co's Short Interest Wells Fargo & Co (NYSE: WFC) has seen a notable decrease in its short interest as a percentage of its float. Recent reports indicate that this short interest has declined by 21.17%, now tallying 34.57 million shares sold short. This represents about 1.08% of all the regular shares available for...

Continue Reading
Encryption as a Service Experience Exceptional Market Growth

Updated Category News Views 121

Exploring the Rapid Growth of Encryption as a Service The Encryption as a Service market is undergoing significant transformation as businesses embrace more robust security measures. With the global market projected to soar from USD 1.57 billion in the coming year to an impressive USD 5.98 billion by 2030, this growth is primarily driven by accelerated cloud adoption and...

Continue Reading
Unlocking Maximum Profits with BexBack's Trading Features

Updated Category News Views 129

Seizing Crypto Trading Opportunities with BexBack As cryptocurrencies gain renewed momentum, savvy traders are exploring innovative platforms to take advantage of market fluctuations. BexBack, a front-runner in the crypto futures arena, is leading the charge with compelling offerings designed to enhance trading experiences. Recent trends indicate that with Bitcoin...

Continue Reading
Liminal Health Unveils NSA ClearPath for Better Reimbursements

Updated Category News Views 389

Transforming Reimbursement with NSA ClearPath Liminal Health is thrilled to unveil NSA ClearPath, an innovative software solution specifically designed to support out-of-network healthcare providers in navigating the complexities of the No Surprises Act (NSA). This groundbreaking platform emphasizes automation, scalability, and transparency, equipping healthcare providers...

Continue Reading
New Found Gold Sees Exciting Drill Results at Dropkick Zone

Updated Category News Views 212

Exciting Drill Results from New Found Gold Corp. New Found Gold Corp. (TSXV: NFG) recently delivered promising results derived from five diamond drill holes in a step-out program at the Dropkick Zone, part of their larger exploration efforts. This area is situated within the Kingsway property, a strategic asset in the company's portfolio. The latest findings indicate...

Continue Reading