Working with Strings
In this guide, we explore how to use the split() and slice() functions; split() allows you to separate a string into an array and slice() allows you to retrieve a range of characters from a particular string.
Sometimes you’ll want to replace the contents of a string. That’s where the replace() method comes in. Using replace(), you can replace a letter, word or phrase in a string with another phrase. We discuss how to use replace() in the above tutorial.
Loops and Conditionals
Programmers use loops to repeat common actions. This reduces the need to copy and paste code, and helps coders maintain a clean and readable codebase. Conditionals are used to decide when certain blocks of code should be met.
“if...else” statements allow you to check if a condition is met. If that condition is met, the code in your “if” statement will run; otherwise, the code in your “else” statement will be executed. You can use “else if” to check for multiple conditions.
Coding is difficult, so it’s no wonder programmers aren’t perfect. What matters is not whether your code is perfect, but whether it can handle errors if they appear. “try...catch” statements allow you to effectively handle errors in your code.
Functions and Lists
In programming, lists allow you to store similar values in the same variable. This means you don’t have to declare multiple variables for values that have something in common. Functions allow you to group together a set of statements that performs a task.
With a function, you can write code once for a common process in your program. A function can be referenced anywhere in your code and can be reused multiple times. For instance, a function could be used to validate a form input for a website.
When you’re working with a list, you may want to find items that meet specific criteria. In this guide, you’ll learn how to use the filter() function to find items in a list. You’ll also learn how to use the reduce() function to perform calculations on a list.
The shift() and unshift() methods allow you to remove and add items to the start of a list. For instance, you could use the shift() method to add the name of a student to a list of student names and then use unshift() to remove that student’s name from the list.
- How to use the forEach method
- How to use the startsWith and endsWith methods
About the author