Taking action, whether it’s the first step in learning a new hobby, or moving across the country to your dream city, can be an exciting experience.
Learning how to code and build your website may seem overwhelming at first. You may be thinking, “one forgotten character and my entire code is wrong.” You’re not alone in that thought, but it’s best to simply roll up your sleeves and get started.
|Related: JavasScript and Java, while they sound similar, are not the same thing!|
Photo courtesy of Colourpop.com
|Related: Check out these tips for coding websites if you're a beginner!|
Fixed values, or literals, come in various forms. They can be numbers, written with or without decimals, or strings of text, written with double or single quotes.
var blogName = ‘G2 Learning Hub’;
var a = 2;
let b = 4;
const c = a + b;
It’s common to think of variables like algebra. So in this case, const c would equal 6. The equal sign is used to assign the values to the variables and is referred to as an assignment operator. The plus sign is referred to as an arithmetic operator, which computes values.
When you name your variables, keep in mind these names need to be unique names, which are called identifiers. They can be short names (like a and b) or more descriptive (like age and sum).
When picking names for your variables, or unique identifiers, keep in mind:
var lastname, lastName;
lastname = ‘Jones’;
lastName = ‘Smith’;
To do so, I would type:
alert (“Hello, welcome to the G2 Learning Hub”)
In this case, alert is a built-in “action” that translates to the browser to display an alert box, and the text is the string.
When I press enter, I get this popup:
var name = “Mara”
Then, I simply typed name and then hit enter, and it knew my name is Mara. For the alert I typed: alert(name), hit enter and received this popup.
Once I used the code to specify my name and put it in quotes, the code knew that the string for name is Mara.
If I were to try and do an alert for a string I have not yet created or defined, alert (message), I’ll receive an error.
Check out our website building hub where you can get 50 resources for free!
Mara is a Senior Content Marketing Specialist at G2. In her spare time, she's typically at the gym polishing off a run, reading a book from her overcrowded bookshelf, or right in the middle of a Netflix binge. Obsessions include the Chicago Cubs, Harry Potter, and all of the Italian food imaginable. (she/her/hers)
Subscribe to keep your fingers on the tech pulse.