I am currently in the middle of working with a brand new API and while I will usually test APIs using Insomnia or using JavaScript’s built-in 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…
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.
Strict mode in JavaScript is a literal expression that you add into your code that lets the compiler know to execute your code in “strict mode”. To use “strict mode”, you can place the expression, “use strict”
at the beginning of your code so that it is globally scoped, or you can place…
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…
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…
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.
The .toLocaleString()
method is a simple one in that it takes one argument with options.
MDN notes:
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.
The .match()
method takes one argument: RegExp
.
You will use .match()
as a property on your string value that you are testing, and inside the parentheses, you will put your…
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.
…
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…
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…