JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – does the string startsWith() method return true

JavaScript Quiz – does the string startsWith() method return true

String starts with method

In javascript, the string startsWith() method is used to check whether the string starts with a specified string. String startsWith() method return a boolean value. Which the return value either true or false.

Basic Syntax

startsWith()

For more detail about the String startsWith() method click here.

JavaScript Question

In this javascript quiz, find out does the string startsWith() method return true because startsWith() method return boolean value.

First, we declare a variable name using let keyword and assign a javascript string to it which is “JS Startup“.

let name = "JS Startup";

In the second step, we will check does the name variable string starts with “J” and print its value using a console log.

console.log(name.startsWith("J"));

Now, we will again check for same alphabet but with small case.

console.log(name.startsWith("j"));

Any idea, what should be the output above two statements.

JavaScript Quiz Test

Here is the full code snippet for you to solve.

let name = "JS Startup";

console.log(name.startsWith("J"));
// output => 🧐 ?

console.log(name.startsWith("j"));
// output => 🧐 ?

// Made with ❤️, by @jsstartup

Answer – true, false

Click To Run Code

Explanation

Now, you know the answer is true, false. But why didn’t name string starting with the same alphabet? Let me explain.

Note: The startsWith() method is case sensitive.

JavaScript is case sensitive which means the capital letter “A” will be equal to “a”. So, if you see the above not then the same case happens with the startsWith() method.

At last, That’s why we get an answer true, false“.

Let me know in the comment section, what you think about it.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JS Quiz – three dots with string variable will expand
  2. JavaScript Quiz – solve 2d array matrix diagonal addition
  3. JavaScript Quiz – find numbers difference with math abs
  4. JS Quiz – does get date and month from date object is same

Conclusion

To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
0 Shares
Share via
Copy link