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

EnGenius Names Experienced VP to Boost Sales Growth

Updated Category News Views 3

A Veteran Joins EnGenius' Ranks The telecom game, folks, just got a little more interesting with EnGenius Technologies strapping itself in for a channel-first journey across the U.S. and Canada. They've placed a seasoned player, Rachel Saunders, into the cockpit as Vice President of Sales, North America. Her resume reads like a telecom scout's dream: 17 years in electric...

Continue Reading
Celebrating Appalachian Soul with Aristotle Jones

Updated Category News Views 6

Igniting a Celebration of Appalachian Soul Now here's a sound that hits you right in the gut. Aristotle Jones, known out there as the 'Appalachian Soul Man,' is making a big move. He's laying out the plan to make July the Appalachian Soul Month. This fellow isn't shy about celebrating the deep roots of Appalachian music, dropping his album Appalachian Soul Power and a new...

Continue Reading
Omneky Integrates AI Growth Agent With Slack for Ads

Updated Category News Views 5

Omneky's New Move: AI Growth Agent Meets Slack Picture this: You've got a marketing team hustling in the digital age, and now they've got a new ally. Omneky, the big-wig in autonomous AI growth, has snuck its AI Growth Agent right into Slack. This isn't just a party trick during Dreamforce week in San Francisco. This is Omneky throwing another cog into the advertising...

Continue Reading
Metriport Eyes Major Step in Health Data Integration

Updated Category News Views 6

Metriport's Push into the TEFCA Framework Son of a gun, Metriport's making noise in the health data world! They just got the nod as a Candidate QHIN under the Trusted Exchange Framework and Common Agreement, or TEFCA if you're into acronyms. This isn't just some digital high-five; it's a significant stride forward for healthcare data exchange. Now they're smack in the...

Continue Reading
Airswift's Strategic Acquisition Boosts U.S. Energy Presence

Updated Category News Views 6

What's Driving Airswift's Latest Expansion? Airswift just dropped a bombshell by snapping up key businesses from New Tech Global (NTG), marking a serious power move in the U.S. energy sector. Now, what does this actually mean for investors? In blunt terms: they're muscling up their contractor base by a meaty 30%. That's no small feat. It's a calculated step to ace the...

Continue Reading
Piedmont Orthopedics Expands Care in Henry County

Updated Category News Views 49

A Surgeon's Story Comes to Henry County Ah, the medical field. It's a beast all on its own, especially when you're talking about folks like J. Hunter Matthews, M.D. making waves in the orthopedic world. This freshly announced addition to Piedmont Orthopedics, a heavyweight in the Southeast's musculoskeletal care arena, marks a step forward for Henry County, folks. We're...

Continue Reading
Foodcare Proves Effective in Reducing Blood Sugar Levels

Updated Category News Views 6

A New Chapter for Diabetes Care: Foodcare Folks, we've got ourselves a game-changer in the world of diabetes care. Listen closely: Foodsmart's latest study, hot off the press from the American Heart Association's Circulation, essentially hands over the blueprint for tackling type 2 diabetes in an innovative fashion. Now, I'm not the type to get all mushy over scientific...

Continue Reading
Andover Audio's FreePlay: Stereo Sound Goes Portable

Updated Category News Views 7

If there's one thing I've seen grow in leaps and bounds, it's the audio world. Andover Audio’s latest move? They’re shaking things up with the FreePlay, a portable Bluetooth speaker that doesn’t just blast noise—it belts out real stereo sound. Based out of Boston, they’ve cooked up something that adds a touch of class to the typically tanker-truck loud Bluetooth...

Continue Reading
Bud Ecosystem Debuts AIOS, Aims to Slash Costs

Updated Category News Views 7

AI Fragmentation Tax: Cut It Out! Look, if you think AI is all about fancy algorithms and self-learning voodoo, you're missing the plot. It's the nuts and bolts—the infrastructure—that's been bleeding enterprises dry. That's where Bud Ecosystem comes thrashing in with its Novaria AIOS. They're not just promising a tiny tune-up; they're talking slashing AI costs by a...

Continue Reading
EmpowHer Grants Propel Female-led Social Ventures Forward

Updated Category News Views 9

Every now and then, you stumble upon a story that makes you take off your trading hat and put on your 'citizen of the world' one. The Boundless Futures Foundation is doing just that, pushing past the $1.5 million mark in grant funding to back female founders creating real scale impact. If this doesn't sound like a nonprofit turning the gears of change, I don't know what...

Continue Reading

Top 5 Most Recently Viewed Articles

Altria’s Slip: Understanding Recent Stock Decline and Future Prospects

Updated Category News Views 156

Insights into Altria Group, Inc. Altria Group, Inc. (NYSE: MO) is experiencing notable challenges in the stock market, with shares of the company declining recently due to sluggish performance in both smokeable and oral tobacco sales. These trends played a significant role in affecting year-over-year revenue growth. Current Earnings Report Analysis Altria reported an...

Continue Reading
Boeing's Workforce Restructuring Amidst Strike and Losses

Updated Category News Views 135

Boeing Faces Major Changes Amid Strikes and Financial Lose Boeing has announced plans to cut 17,000 jobs, which represents about 10% of its global workforce, as it deals with ongoing financial struggles following a month-long strike. The company's decision comes after striking workers halted the production of critical airplanes, including the 737 MAX and the 777. This...

Continue Reading
Renting vs. Buying a House in 2024: A Comprehensive Guide

Updated Category Personal Finance Views 593

Navigating the housing market in 2024 presents a unique set of challenges and opportunities for those standing at the crossroads of renting and buying. With fluctuating market trends, changing interest rates, and the evolving needs of individuals, the decision to rent or buy is more significant than ever. This blog post aims to shed light on the pros and cons of each...

Continue Reading
Talen Energy Launches $600 Million Financing and Stock Repurchase

Updated Category News Views 95

Talen Energy Sets the Stage with $600 Million Financing Talen Energy Corporation, a notable player in the energy sector, has recently announced an exciting financial move, introducing a $600 million Term Loan B financing initiative. This strategic decision is poised to significantly bolster the company’s liquidity and enhance its existing capital structure. By...

Continue Reading
Insights into MuniFin's Financial Stability and Growth Strategies

Updated Category News Views 123

MuniFin Group’s Pillar III Half Year Disclosure Report MuniFin Group, known formally as Municipality Finance Plc, has officially released its Pillar III Half Year Disclosure Report for 2025. This report adheres to important regulations, specifically Regulation (EU) No 575/2013 and Directive 2013/36/EU. It's crucial for investors and interested parties to remain informed...

Continue Reading