- This method is used to test for a match inside a string variable.
test()method will return true if a match is found, just like a regular conditional statement. In other case, it will return false.
test() Function Explained
test() function will return a boolean value. If the string contains the characters you typed in, the method will return true. When the string does not contain any matches, false is
The following code snippet illustrates the way the
var sampleString = "Testing testing"; var samplePattern = new RegExp("t"); var sampleResult = samplePattern.test(sampleString);
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid certificates of completion
- Professional service
- Flexible timetables
- A variety of features to choose from
- Professional certificates of completion
- University-level courses
- Multiple Online degree programs
- Great user experience
- Offers quality content
- Very transparent with their pricing
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
Write The Method Correctly
.test function will not give you a headache. If you have at least a tiny bit of experience in programming, you will quickly grasp the way the function needs to be included in your code:
regExpObject defines the pattern you will be looking for. Then, there is a required parameter called string which indicates the string to be searched for specified characters or words.
What Method Returns
In our case, true indicates that matches of the pattern you specified were successfully found. However, if the outcome is false, that means no matches were detected in a string.
Latest Udacity Coupon Found:
75% OFF COURSES
Udacity Black Friday Offer
The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!