02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoPrevious Video

Strings

<p>We will often be working with strings, so let&rsquo;s take a look at some common manipulations we can do to them using JavaScript.</p> <h3>Naming Conventions</h3> <p>Every variable has a unique name which differentiates it from other variables. One important thing to remember about JavaScript is that it&rsquo;s a CASE SENSITIVE language. In other words if you create a variable named <b>string1</b> and you want to use this variable anywhere in your JavaScript, you can&#39;t refer to it as &#39;String1&#39;: JavaScript will puke! (The difference is only the capital &lsquo;S&rsquo;.) If you forget this tidbit of information, you&#39;re begging for trouble. </p> <p> Note: If we are talking about variable names, it&#39;s important to note that in JavaScript and many other programming languages the standard is to camel case variables: always start with a lower case letter. In our case we would prefer &#39;string1&#39; and not &#39;String1&#39; as our variable name. More on why we do that later.</p> <p>Since we&rsquo;re talking about variables, here&rsquo;s some sound advice. As you&rsquo;ll be using a lot of them in your programming, we suggest you always create variables which have a useful name. If you want to create a variable to hold the first name of a person, don&rsquo;t name it it something random like &lsquo;var cow;&rsquo;. Use names that describe the variable&#39;s content such as &lsquo;var firstName&rsquo;. The more descriptive your variable names are, the more readable your code will be. </p> <p>In most programming languages, when you finish writing one line of code you end it with a semi colon &ldquo;;&rdquo;. If you don&rsquo;t, an error might be displayed. JavaScript is a forgiving language: if you don&#39;t use the semi colon you might not get an error (you don&rsquo;t want to rely on this particular MIGHT!) It&#39;s good programming practice so I&rsquo;m going to encourage you to use the semi colon whenever you end a line of code.</p> <h3>Using Variables with Strings</h3> <p>Getting back to creating variables in JavaScript, let&#39;s take a deeper look into the creation of a variable:</p> <p> <i>var firstString = &ldquo;Hello Earth&rdquo;;</i></p> <p>We just created a string which is stored in the variable firstString. Now, what is a function? A <b>function</b> is a piece of code which performs a task. For example JavaScript has a function called alert(&ldquo; &rdquo;). This function&#39;s job is to take a string input and display it in the client&#39;s browser as a pop-up message. If we pass this function the string which we just created like this: <b>alert(firstString);</b> when the page loads, a pop-up message will appear saying &ldquo;Hello Earth.&rdquo; </p> <p>JavaScript offers a lot of ways to manipulate strings. Imagine you want to combine two strings together. All you need is a PLUS(+) sign. For example: </p> <p><i>var firstString = &ldquo;Hello Earth&rdquo; + &ldquo;, I am back&rdquo;;</i> </p> <p>What happened here? The + sign joined the two strings together and stored it in the variable firstString: now firstString has &ldquo;Hello Planet, I am back&rdquo; stored in it.</p> <p>The same can be done with variables. For example if we have var testString = &ldquo;Hello People&rdquo; what happens when we call alert like this:</p> <p><i>alert(testString + testString); </i> </p> <p>You got it right if you guessed we get a pop up box showing &ldquo;Hello People Hello People.&rdquo; String variables can also be joined using the magical + sign.</p> <p>What&rsquo;s the point of this lecture and all these tips? As you gain experience as a programmer you will realize how important it is to have clean code with meaningful variables. It not only helps you but it helps anyone who reads it to manage and understand your code. </p>

Intro

It's never been easier to start learning programming in JavaScript. We live in an HTML5 world: what would be better than learning how to code with JavaScript and HTML5?

03:59

The Script Tag

You must know about script tags in order to code in JavaScript, so let’s jump into it and learn with style!

04:26

OOP and DOM

Two basics which are very important in programming and provide discipline which helps you learn and stay organized

02:45

What are Variables?

Variables are the building blocks of any language, so it's best to be very familiar with them and their usage.

01:37

Strings

Strings are an important part of programming; they can be manipulated, passed as parameters and a lot more.

10:39

Creating Javascript Comments

Comments are a great asset of programming. They will help make the code more understandable and manageable

00:52

Numbers

Math is everywhere; numbers are everywhere. JavaScript lets us use them and apply math on them, so let’s have fun and learn about Numbers in JavaScript.

09:29

Boolean

Booleans help us make important decisions in programming by proving yes or no information.

09:10