Learn How to Code
  • Welcome
  • Foundations
    • Introduction
      • Becoming a web developer
      • Motivation and mindset
      • Join a supportive community
      • How does the web work?
    • Requirements
      • Prerequisites
      • Text editors
      • Command line basics
      • Setting up Git
      • Setting up Node
    • Git
      • Git basics
      • Project: Practicing Git
    • Frontend
      • HTML and CSS
      • Developer Tools
      • Project: Create a web page
    • JavaScript
      • Strings and Conditionals
      • Using Developer Tools
      • Functions
      • Problem solving
      • Project: Rock paper scissors
      • Writing clean code
      • Arrays and Loops
      • The DOM
      • Project: Etch-A-Sketch
      • Objects and More Arrays
      • Project: Calculator
    • Backend
      • Frameworks
    • Next steps
  • Deep dives
    • Computer Science
      • Pseudocode and algorithms
      • Recursion and algorithms
        • Project: Fibs and sorting
        • More on algorithms
        • Big O
        • Project: Practicing Big O
      • Data structures
        • Maps, Stacks and Queues
        • Project: Stacks and Queues
        • Nodes, Linked Lists and Trees
        • Project: Linked Lists
        • Project: Trees
        • Next steps
    • Databases
      • Databases and SQL
      • Project: SQL Zoo
    • Design / UX
      • Fonts and typography
      • Grids
      • Project: Teardown
      • Responsive design
      • Project: Mobile friendly
      • CSS frameworks
      • Project: Bootstrapping
    • HTML / CSS
      • HTML Basics
        • Linking
        • Images and media
        • Project: Embedding media
        • HTML5
        • Tables
        • Lists
        • Forms
        • Project: Make a form
      • CSS Basics
        • Box model
        • Floats and positioning
        • Flexbox
        • Grids
        • Project: Breaking news
        • Best practices
        • Backgrounds and gradients
        • Project: One more thing
        • CSS3
        • Preprocessors
        • Project: Your own framework
      • Next steps
    • JavaScript
      • Refresher
      • Organization
      • Objects and constructors
      • Project: Library
      • Factory functions and module patterns
      • Project: Tic Tac Toe
      • Classes
      • ES6 Modules
      • Project: Restaurant
      • Object Oriented Programming
      • Project: Todo list
      • Linting
      • Menus and sliders
      • Forms
      • ES6 features
      • JSON
      • Callbacks and promises
      • Using APIs
      • Async and Await
      • Project: Weather
      • Testing
      • Project: Testing 1-2-3
      • Advanced Testing
      • Project: Battleship
      • Backends
      • Project: Where's Waldo?
      • Project: All-Star
      • Next steps
    • NodeJS
      • Project: Going to school
      • Project: Passing the test
      • Express
        • Templates and middleware
        • CRUD and MVC
        • Project: Message board
        • Routes
        • Displaying data
        • Forms and deployment
        • Project: Inventory
      • Authentication
      • Security
      • Project: Clubhouse
      • APIs
      • Securing an API
      • Project: Blog
      • Testing
      • Testing with a database
      • Project: Social network
    • React
      • Props and State
      • Render lists and handle inputs
      • Project: CV
      • Lifecycle methods
      • Hooks
      • Project: Memory card
      • Router
      • Project: Shopping cart
      • Advanced concepts
    • Ruby
      • Installation
      • Data types
      • Variables
      • Input and Output
      • Conditionals
      • Loops
      • Arrays
      • Hashes
      • Methods
      • Enumerables
      • More enumerables
      • Nested collections
      • Blocks
      • Pattern matching
      • Debugging
      • Project: Caesar cipher
      • Project: Substrings
      • Project: Stock picker
      • Project: Bubble sort
      • Object oriented programming
      • Project: Tic Tac Toe
      • Project: Mastermind
      • Serialization
      • Project: Event manager
      • Project: Hangman
      • Computer Science
        • Recursion
        • Project: Merge Sort
        • Data structures and algorithms
        • Project: Linked Lists
        • Project: Binary Search Trees
        • Project: Knight Travails
      • Testing
      • RSpec
      • Project: Four in a row
      • Git
      • Project: Open Source
      • Project: Chess
      • Next steps
    • Ruby on Rails
      • Using Heroku
      • Installing Rails
      • Basics
        • Routing
        • Controllers
        • Views
        • Asset pipeline
        • Deployment
        • Project: Blog
      • Active Record
        • Project: Upvote
      • Forms
        • Cookies, sessions, and authentication
        • Project: Password
      • Advanced forms and Active Record
        • Associations
        • Project: Private Events
        • Callbacks
        • Menus, helpers and nested forms
        • Project: Ticket agent
      • APIs
        • External APIs
        • Project: Animals
        • Project: Photo widget
      • Mailers
        • Project: Confirmation
      • Advanced topics
        • Action Cable
      • Project: Social network
      • Next steps
  • Getting hired
    • Preparing to find a job
      • Plan a strategy
      • What companies want
      • Get yourself together
      • How to prepare
      • Project: Make your website
    • Applying and interviewing
      • Qualifying leads
      • Project: Make your resume
      • Applying for jobs
      • Preparing for an interview
      • Handling an offer
      • Final words
  • Maintained by
    • wbnns
  • License
    • CC BY-NC-SA 4.0 © 2022
Powered by GitBook
On this page
  • Overview
  • Learning outcomes
  • Strings
  • Conditionals
  • Practice
  • Additional resources
  1. Foundations
  2. JavaScript

Strings and Conditionals

Learn the basics about strings, booleans and conditionals in JavaScript.

PreviousJavaScriptNextUsing Developer Tools

Last updated 4 years ago

Overview

There are a few extremely common types of data that you will encounter in JavaScript, and these fundamentals lessons will give us a really strong foundation in all of them. Before we start digging deep, however, will give you a quick overview of the most common ones.

Learning outcomes

Look through these now and then use them to test yourself after doing the assignment:

  • What are the eight data types of javascript?

  • Which data type is NOT primitive?

  • What is the difference between single, double, and backtick quotes for strings?

  • Which type of quote lets you embed variables/expressions into a string?

  • How do you embed variables/expressions into a string?

  • How do you escape characters in a string?

  • What is the difference between slice/substring/substr?

  • What are methods?

  • What are the three logical operators and what do they stand for?

  • What are the comparison operators?

  • What is nesting?

  • What are truthy and falsy values?

  • What are the falsy values in JavaScript?

  • What is the syntax for an if/else conditional?

  • What is the syntax for a switch statement?

  • What is the syntax for a ternary operator?

  • What is the relationship between null and undefined?

  • What are conditionals?

Strings

Depending on what kind of work you're doing, you might end up working more with pieces of text rather than numbers. A string is simply a piece of text... and is a fundamental building block of the language.

Conditionals

Now it's time for the fun stuff... So far we haven't done much with our programming that you couldn't do with simple math skills. Sure, we've told our computer how to do the math, so that makes it quicker, but the essence of programming is teaching the computer how to make decisions in order to do more involved things. Conditionals are how we do that.

Practice

To give you a good bit of practice, we have created some repl.it exercises for you to play with. We believe that it's best to practice programming on your own computer, rather than in an online environment, but we'll get to that soon enough.

Be sure to do the lessons in order presented here. Pressing "run" at the top will run the code. Read all directions, watch the terminal, and read all the errors. Don't forget to use 'console.log' extensively.

To get started, create a free repl account and click "Fork" in order to have access to the exercises. Note: Feel free to browse the files on the left column in order to gain familarity with it.

    • In this exercise, you will be working out of the file called troubleshooting.js

    • You will be working out of script.js

    • You will be working out of math.js

    • You will be working out of follow.js

Additional resources

This section contains helpful links to other content. It isn't required, so consider it supplemental for if you need to dive deeper into something.

Read and code along with on the topic.

Go through to learn a bit more about what you can do with strings... be sure to do the exercises at the end!

Vocabulary time: a method is a bit of functionality that is built into the language or into specific data types. In , you learned a few methods that can be used on strings, such as indexOf and search. An exhaustive list of methods that can be used on strings can be found .

Step one in learning about conditionals is making sure you have a good grasp on .

is a great first glance at conditionals in JavaScript.

will teach you about logical operators.

reinforces the concept and provides several interesting examples of how you could use it building websites.

covers the same basic concept (read through it as a review!) and - more importantly - offers the usual 'tasks' at the bottom of the page!

teaches you about the switch statement, which comes in handy when you have multiple conditions.

this article
yet another MDN tutorial
this lesson
the previous W3Schools exercise
here
comparisons
This tutorial
This tutorial
This article
This article
This tutorial
Exercise 1
Exercise 2
Exercise 3
Exercise 4
The Net Ninja's Regular Expressions Tutorial