fetch function, I have decided to learn a little more about bash and scripting. This has led me to cURL and all of its wonderfulness for making HTTP requests quickly in my terminal.
cURL or ‘client URL’ is a command-line utility that is used for file transfers using a URL. Curl is universal and many people have access to it already if you are on a UNIX based machine, which is why it is such a popular choice for making HTTP requests. …
When I started learning JS, I learned the language by always having to write out my functions using the function keyword.
I have been writing my recent blog posts to reflect the ways in which I am trying to clean up and make my JS code more readable. One of those ways I want to talk about in this blog post is implementing “strict mode” into your code.
“use strict” at the beginning of your code so that it is globally scoped, or you can place it within specific functions or blocks. …
In my last blog post, I wrote about using switch statements when I don't need complicated
if-else statements. It makes my code easier to read and overall just easier to manage. In keeping up with trying to clean up my conditional statements, I have been implementing more ternary operations into my code. Now I have usually avoided them just because I was just used to writing
if-else statements, but honestly, less is more and if you don't need to type out a multiline statement, why not use a ternary operator? Let me show you why they are great!
To write a ternary…
Something I am trying to get in the habit of using when I do not need complicated
if-else statements are
switch statements. Switch statements are great for comparing multiple options such as in the case of checking if a string matches a certain word or number. One example that comes to mind is a card game. You can check if your value is equal to a “J”, “K”, etc., and depending on the match, have the switch statement do something. Let’s get started on this tutorial.
For the switch statement to work, we have to write the keyword
switch and inside of the parenthesis, we give it an argument that we want to be compared. The switch statement works with strict equality so if you are expecting to compare values in the way that you would use
== , I would go ahead and use a regular
if-else statement. …
I ran into a problem while doing a project on trying to convert currency. It wasn't the issue of doing the conversion, but what if I wanted the numbers to be separated by commas or periods? In the US, for the price of five thousand dollars, it is common to write it like $5,000.00, but in another country, it might be written like €5.000,00. I will show you how you can go about doing that in two ways.
.toLocaleString() method is a simple one in that it takes one argument with options.
While I take a break from my RegEx series, I wanted to write an article that was still related to regular expressions. I recently learned about the
.matchAll() method, which I had not used until this past week.
I had mentioned in this article how to match a pattern and extract it into an array using the
.match() method. You’ll see that
.matchAll() works similarly to
.match() with slight differences.
You will use
.match() as a property on your string value that you are testing, and inside the parentheses, you will put your
RegExp pattern. The return value will be an array of all the matches or an empty array. The returned array will be dependent on the
g (or global) flag that returns all occurrences of the pattern you want to match. …
Alternate characters in regular expressions can be very useful in addition to the many ways I have previously shown you in this series to match patterns. I’ll first start with the
| pipe symbol which works very much the same way as it does in our conditional statements, functioning as ‘or’. Second, I’ll show you how to also use the
() parenthesis in the regular expression to create capture groups as well to help specify which character we want to only be looking at first.
Again, if you want to follow along, I will be using the free site regex101.com.
The pipe symbol in a regular expression allows you to use a conditional to search for the pattern you want by way of the ‘or’ statement. …
One thing I like using regular expression for is when I need to match a pattern that is at the beginning or end of a string. In this post, I will quickly show you how to do that!
To start with matching the start of the string, we will use the
^ symbol. You can use either the character sets as I have shown previously or literal character matches. You will put the carat symbol before the pattern you are trying to match like this:
/^<insertPatternHere>/(optional flags here)/
I have chosen the literal string “cat.” I want to match any string that begins with the literal characters of “cat”. As you can see on the first line, it matches the first string, but on the second line, it does not match because that string starts with the string “dog”. Finally, our last string is matched because that one does start with “cat”. …
This is the final installment of my special characters post within my regular expressions series. I will mention in this post, the wildcard character, optional character, and the zero or more repetitions character.
Let’s start with the optional character as that one is my favorite. I will be using regex101.com again to create the examples. If you want to follow along, you can use that website as it is an excellent tool for testing your regex.
The optional character uses the
? in the regular expression. If you want to match a pure question mark for punctuation purposes, you will have to escape it like all special characters using the backslash