Check if Absolute URL

JavaScriptJavaScriptBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this lab, we will dive into the world of JavaScript programming and explore various concepts such as variables, data types, conditional statements, loops, and functions. Through a series of hands-on exercises and coding challenges, you will learn how to write clean and efficient JavaScript code, and gain a solid understanding of the fundamental principles that underpin this powerful programming language. By the end of this lab, you will be equipped with the skills and knowledge needed to tackle more complex JavaScript projects with confidence.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL javascript(("`JavaScript`")) -.-> javascript/BasicConceptsGroup(["`Basic Concepts`"]) javascript(("`JavaScript`")) -.-> javascript/SecurityGroup(["`Security`"]) javascript/BasicConceptsGroup -.-> javascript/data_types("`Data Types`") javascript/BasicConceptsGroup -.-> javascript/arith_ops("`Arithmetic Operators`") javascript/SecurityGroup -.-> javascript/web_sec("`Web Security Basics`") subgraph Lab Skills javascript/data_types -.-> lab-28406{{"`Check if Absolute URL`"}} javascript/arith_ops -.-> lab-28406{{"`Check if Absolute URL`"}} javascript/web_sec -.-> lab-28406{{"`Check if Absolute URL`"}} end

Function to Check if a String is an Absolute URL

To check if a given string is an absolute URL, follow these steps:

  1. Open the Terminal/SSH and type node to start practicing coding.
  2. Use RegExp.prototype.test() to test if the string is an absolute URL.
  3. The function should be defined as const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
  4. The function takes a string argument str and returns true if the string is an absolute URL, and false otherwise.
  5. Test the function using the examples provided:
isAbsoluteURL("https://google.com"); // true
isAbsoluteURL("ftp://www.myserver.net"); // true
isAbsoluteURL("/foo/bar"); // false

Summary

Congratulations! You have completed the Check if Absolute URL lab. You can practice more labs in LabEx to improve your skills.

Other JavaScript Tutorials you may like