String starts with method
For more detail about the String startsWith() method click here.
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.
Now, we will again check for same alphabet but with small case.
Any idea, what should be the output above two statements.
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
Now, you know the answer is true, false. But why didn’t name string starting with the same alphabet? Let me explain.
startsWith() method is case sensitive.
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 –
- JS Quiz – three dots with string variable will expand
- JS Quiz – does get date and month from date object is same
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.