Forgot username/password? Don't have an account?
Login with Facebook
Home » Courses » JavaScript 101 » Strings
Subscribe for updates.
* New to us? log in with Facebook and get a free day pass

JavaScript 101

  1. Intro (03:59)
  2. The Script Tag (04:26)
  3. OOP and DOM (02:45)
  4. What are Variables? (01:37)
  5. Strings (10:39)
  6. Creating Javascript Comments (00:52)
  7. Numbers (09:29)
  8. Boolean (09:10)


We will often be working with strings, so let’s take a look at some common manipulations we can do to them using JavaScript.

Naming Conventions

Every variable has a unique name which differentiates it from other variables. One important thing to remember about JavaScript is that it’s a CASE SENSITIVE language. In other words if you create a variable named string1 and you want to use this variable anywhere in your JavaScript, you can't refer to it as 'String1': JavaScript will puke! (The difference is only the capital ‘S’.) If you forget this tidbit of information, you're begging for trouble.

Note: If we are talking about variable names, it'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 'string1' and not 'String1' as our variable name. More on why we do that later.

Since we’re talking about variables, here’s some sound advice. As you’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’t name it it something random like ‘var cow;’. Use names that describe the variable's content such as ‘var firstName’. The more descriptive your variable names are, the more readable your code will be.

In most programming languages, when you finish writing one line of code you end it with a semi colon “;”. If you don’t, an error might be displayed. JavaScript is a forgiving language: if you don't use the semi colon you might not get an error (you don’t want to rely on this particular MIGHT!) It's good programming practice so I’m going to encourage you to use the semi colon whenever you end a line of code.

Using Variables with Strings

Getting back to creating variables in JavaScript, let's take a deeper look into the creation of a variable:

var firstString = “Hello Earth”;

We just created a string which is stored in the variable firstString. Now, what is a function? A function is a piece of code which performs a task. For example JavaScript has a function called alert(“ ”). This function's job is to take a string input and display it in the client's browser as a pop-up message. If we pass this function the string which we just created like this: alert(firstString); when the page loads, a pop-up message will appear saying “Hello Earth.”

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:

var firstString = “Hello Earth” + “, I am back”;

What happened here? The + sign joined the two strings together and stored it in the variable firstString: now firstString has “Hello Planet, I am back” stored in it.

The same can be done with variables. For example if we have var testString = “Hello People” what happens when we call alert like this:

alert(testString + testString);

You got it right if you guessed we get a pop up box showing “Hello People Hello People.” String variables can also be joined using the magical + sign.

What’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.

Got A Question?

'I love being Prime'

Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.

Act now while we have available seating

Our on line school is private, affordable and interactive with trainer support.
Act now save your seat before someone else takes yours.
Act now