Strings, Conditionals & logical operators Copy

Learning objectives:

Let’s keep moving on and learning new concepts in javascript, in this topic we will get familiar with:

  • New Javascript data type -> strings.
  • How to declare a string variable in javascript.
  • JavaScript String Operators (concatenation).
  • Common javascript string methods.
  • Conditionals
    • logical operators (AND ,OR, NOT).
    • syntax of if, else and else if statements in javascript.
    • Ternary operator.
    • javascript switch statement.

Study: Strings

Strings, likewise numbers, are very important data types in JavaScript. A string is simply a piece of text… and is a fundamental building block of the language.

  1. Read and code along with yet another MDN tutorial on the topic: Handling text — strings in JavaScript. (Dedicate at least 90 minutes on this material)

  2. Go through this lesson: JavaScript String Methods to learn more about what you can do with strings… be sure to do the exercises at the end! Suggested reading and coding time for this material: 90 minutes After reading this post, you must ensure that you have a firm understanding of the following String properties and methods:

  • The .length property
  • The following String methods:
    • indexOf()
    • lastIndexOf()
    • search()
    • slice()
    • substring()
    • substr()
    • replace()
    • RegEx
    • toLowerCase()
    • toUpperCase()
    • concat()
    • trim()
    • charAt()
    • charCodeAt()
    • split()
  1. Let’s now learn what a method is: a method is a bit of functionality that is built into the language or into specific data types. In the previous W3Schools exercise, you learned a few methods that can be used on strings, such as indexOf and search. However there a lot more methods that can be use on strings. An exhaustive list can be found here: String methods.

Study: Conditionals

Up until now we haven’t done much with our programming. We have told the computer to do some math but the the essence of programming is teaching the computer how to make decisions. In other words we need to tell the computer when to do certain things. And the way we do it is with the conditionals.

So now it is time to have fun!

  1. The first step in learning about conditionals is making sure you understand comparisons: – Comparisons. (Estimated reading and coding time for this material: approx. 1 to 2 hours

  2. JavaScript if, else and else if you will get a first glance at conditionals in JavaScript. (Dedicate at least 1 hour on this material)

  3. Logical Operators you will learn about logical operators. (Dedicate at least 1 hour on this material)

  4. Making decisions in your code — conditionals provides several interesting examples of how you could use it building websites. (Estimated reading, practice time and completion of exercises: approx. 10 hours)

Supplementary Material:

  1. Conditional branching: if, ‘?’ covers the same basic concept (read through it as a review!) Furthermore it offers the usual ‘tasks’ at the bottom of the page!

  2. How To Use the Switch Statement in JavaScript will teach you about the switch statement.

BOOKMARK THIS: This last resource has been created by Tania Rascia. Tania is one of the best online educators when it comes to Frontend and web technologies, so make sure to follow here on twitter, join her newsletter and definitely bookmark her website which contains a lot of amazing tutorials and posts. Whenever you find yourself troubled or tangled up in a difficult concept, search Tania’s posts and tutorials for it. Chances are, you will find yourself a clear explanation.

Additional Resources

In this section you can find a lot of helpful links to other content. This is a supplemental material for you if you want to dive deeper into some concepts.

  • Take a 10 to 15 minutes break and watch The Net Ninja’s Regular Expressions Tutorial. Don’t worry if you feel overwhelmed by the concept of Regular Expressions as it’s one of the most difficult and awkward computer languages. All that we want at this point, is for you to gain some basic understanding of how this pattern matching language works and become familiar with this undeniably powerful feature of most programming languages.

  • If you feel comfortable, continue to this site and practice yourself with some easy to medium pattern matching tasks.

Estimated viewing and coding practice time: approx. 3 hours