What Are

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

What Are Variables?

http://lifehacker.com/5736011/learn-how-to-co...data-types

You can think of variables as labeled jars that store different types of data. While there are several kinds of variables, today we're only going to look at three:

  • String - A string variable is a string of alphanumeric characters and allowed symbols that are contained within quotation marks. For example, "Hello world, I'm 102 years old today!" is an example of a string. Strings can also be contained within single quotes, which is useful if you want to have a string with a quotation like this: '"I hate the snow," Laurel said.' Strings are basically used for storing text.
  • Number - A number variable couldn't be more straightforward because all number variables store are numbers. You don't store them within quotes like strings. Instead, numbers can just be written as they are. If you want to store the number 9 in a variable, you just write 9.
  • Boolean - A boolean variable is one of two things: true or false . This data type is kind of like an on and off switch, so you can ask true or false questions in your code. For example, you might ask "is the video currently playing?" The response you'd get would be a boolean variable. True would mean the video is currently playing and false would mean it is not.

So how do you putt a variable to your code (or declare a variable, as it's more traditionally called)? In JavaScript, all you need to do is this:

myVariable = "Hello world!";

To Var or Not to Var

In JavaScript, you can define a variable as myVariable = "something"; or var myVariable = "something"; , the difference being the word var preceding the statement. When you're declaring variables in a script outside of a function, this distinction is pretty much irrelevant. When you're declaring a variable inside a function and do not use var this creates a global variable. Global variables can be accessed from anywhere in your code, whereas local variables (such as the ones defined in functions) can only be accessed within their own scope (e.g. if a variable is local to a function, only that function can use it). This is not an important distinction right this minute, but when we learn about functions later it'll be good to know.

There are a few of things to notice here. First, the name myVariable. All programming languages have something called reserved words, which means you can't use them as variable names. What they varies, but if the name is sufficiently generic, there's a chance it could be a reserved word. To avoid using reserved words and screwing up your code, just decide on a naming scheme for your variables. I've put "my" in front of my example variable, but you'll probably want to come up with something else. Second, you'll notice a semicolon at the end of the line. A semicolon is like a period at the end of a sentence in many programming languages, and that is definitely the case in JavaScript. In nearly every situation, you need to end your code sentences with a semicolon so your computer doesn't get confused when reading it. The semicolon tells the computer, "Okay I'm all done with this statement." (Note: JavaScript is forgiving, and sometimes you can get away without the semicolon, but it's good practice.)

One more thing to note is that JavaScript is a loosely-typed language. There are (basically) two kinds of languages: loosely-typed and strictly-typed. An example of a strictly-typed language is ActionScript (the language Flash apps are written in), and the same variable declaration we just wrote would look like this in ActionScript 3:

var myVariable:String = "Hello world!";

The additions you're seeing are the word var and the word String (with a colon in front of it). The word var tells the computer we're about to declare a variable. The :String attached to the variable's name tells the computer what type of variable it is and to not accept any other type. This is the reason for the term strictly-typed . A loosely-typed language like JavaScript is more flexible and doesn't require any of that. This makes your code more flexible, but some will argue it will also make it more error-prone. We're not going to get into the pros and cons of strictly- and loosely-typed languages here, but it's good to be aware of the basic differences now as you will most likely encounter them in your programming endeavors.

Scroll down for more posts ▼

Top 10 Most Recent News Articles

PASCAL's Holiday Gift Edit: Timeless Watches Shine

Updated Category News Views 185

Fresh Sparkle for the Holidays Well, here we are again, staring down the barrel of another holiday season. And what do you know, PASCAL is out with its 2026 Holiday Gift Edit, like clockwork. This is the kind of stuff they’re good at—capturing a moment, slapping some color on it, and calling it a game-changer. Launching on November 14, this edit nods to their Timeless...

Continue Reading
BETR's Slide: Investors Face Big Losses, Leadership Shift

Updated Category News Views 170

BETR Investors Left in the Lurch It's a real trainwreck, folks. Better Home & Finance Holding Company, trading under NASDAQ:BETR, is in the spotlight for all the wrong reasons. The company expanded the class period for its investor lawsuit to include even more dates between March and August 2026, reflecting a torturous ride for shareholders. Their stock cratered by a...

Continue Reading
Motphys Unleashes MotrixSim 1.0, Aiming at Simulation Dominance

Updated Category News Views 234

Motphys Breaks into the Global Simulation Scene The tech world just got slammed with what might be a seismic shift: Motphys, a bold outfit hailing from China, has dropped its brand-new, homegrown simulation engine, MotrixSim 1.0. It's causing quite the stir, unveiling at the Conference on Robot Learning 2026 (CoRL) and throwing down the gauntlet to Western titans like...

Continue Reading
Fluence Energy Faces Leadership Departures Amid Legal Woes

Updated Category News Views 155

Fluence Energy's Rocky Road Continues It's chaos once again in the halls of Fluence Energy (NASDAQ:FLNC). The ship seems to drift further from solid ground as their CEO and CFO candidly decided to jump ship, shaking investor confidence even more vigorously. The market's reaction was swift and brutal: a nasty 9% share drop, leaving investors with more than just a headache....

Continue Reading
Lilly's Obesity Breakthroughs: A Step Beyond the Scale

Updated Category News Views 143

Pushing the Boundaries of Obesity Treatment Alright, let's cut through the noise and get to what really matters here. Eli Lilly is taking on obesity treatment like it's Clash of the Titans at this year's ObesityWeek 2026 in Washington, D.C. Forget just dropping pounds—Lilly wants to reshape how we think about obesity entirely. They're not just leaning into the scale,...

Continue Reading
Novo's CagriSema Trial Shows Promising Obesity Results

Updated Category News Views 321

Novo's Latest Weight Loss Gamble Well, look what we have here. Novo Nordisk is shaking up the obesity treatment scene with some bold numbers from their REDEFINE 9 trial. The investigational CagriSema combo of amylin analog and GLP-1 receptor agonist has churned out an eyeball-popping near 21% weight loss. For context, we're staring down the barrel of numbers far meatier...

Continue Reading
WeaveGrid Powers EVConnectNC: Charging Incentives Launched

Updated Category News Views 139

Transforming Utilities with EVConnectNC In a fresh move by WeaveGrid, North Carolina's Electric Cooperatives have teamed up to roll out EVConnectNC. This innovative program aims to manage the burgeoning demand for electric vehicle (EV) charging in rural and suburban areas under North Carolina's cooperative umbrella. Think of it as a smart way to handle new loads without...

Continue Reading
Advanta's Game-Changer: Acquiring Misr Hytech to Expand in Africa

Updated Category News Views 249

Advanta's Strategic Move into Africa Alright, let's cut to the chase. Advanta is making a big splash with its acquisition of Misr Hytech, a move that's going to shake things up in Africa's agricultural sector. This isn't just another merger to gloss over with your morning coffee. We're talking about a deal that's supposed to wrap up by January 31, 2027, bringing together...

Continue Reading
CARsgen's CAR-T Breakthrough on China's Insurance List

Updated Category News Views 230

A Game Changer for CAR-T Therapies There's a breeze of optimism blowing from Shanghai these days—a rare sensation in this market of endless skirmishes. CARsgen Therapeutics Holdings Limited, a company entrenched in the development of cutting-edge CAR T-cell therapies, just notched a victory. They've announced that their CAR T-cell therapy product, satricabtagene...

Continue Reading
Luvme Hair Offers Wig Variety for Winter Fashion

Updated Category News Views 313

Adding Flair to Winter Looks A style kick-off from the fashion world: Luvme Hair is flipping the table on winter wardrobes with a new collection of wigs. As the weather ramps up the need for thick coats and cumbersome layers, these long hairstyles offer a little extra swing, bringing dimension into the mix. Fancy a change from traditional winter hibernation? Here’s what...

Continue Reading

Top 5 Most Recently Viewed Articles

Healthcare Realty Trust's Q4 Highlights and Dividend Update

Updated Category News Views 112

Healthcare Realty Trust Quarterly Results Overview Healthcare Realty Trust Incorporated (NYSE: HR) has reported its fourth quarter results for the year 2024, highlighting significant developments in its operations and financial performance. The company recorded a net (loss) income attributable to common stockholders of $(106.8) million, or $(0.31) per diluted share,...

Continue Reading
BGL's Strategic Move: Selling Western Botanicals to Riverside

Updated Category News Views 322

Brown Gibbons Lang & Company (BGL) has just sealed the deal on a significant sale—Western Botanicals, a prominent player in the Vitamins, Minerals, and Supplements (VMS) contract development and manufacturing space, is headed to The Riverside Company. Now this isn’t just another corporate shuffle; it's BGL’s third foray into the CDMO subsector and marks their fourth...

Continue Reading
High Arctic Energy Services Reports Second Quarter 2025 Success

Updated Category News Views 225

High Arctic Energy Services Reports Strong Second Quarter Results High Arctic Energy Services Inc. (TSX: HWO), a noted energy services provider, has recently shared its financial results for the second quarter of 2025, highlighting a continued commitment to operational excellence amid challenging market conditions. 2025 Second Quarter Performance Overview The company...

Continue Reading
DXC Technology Investors Notified of Securities Class Action

Updated Category News Views 45

DXC Technology Class Action Notice for Shareholders The Gross Law Firm has released an important notice for shareholders of DXC Technology Company (NYSE: DXC). This notice is aimed at individuals who acquired shares during the specified class period. Shareholders are encouraged to reach out to the firm if they are interested in being considered for the role of lead...

Continue Reading
Manulife's $750M US Offering: Risky or Strategic?

Updated Category News Views 50

Manulife: Debuting $750M in Subordinated Notes When it comes to Manulife's latest move, it's all about the numbers. They've priced a U.S. public offering of a meaty $750 million in subordinated notes at an enticing 6.146% interest rate. That's no pocket change, folks, and it highlights a strategy or a gamble, depending on your view. But here's the kicker: these notes may...

Continue Reading