al_Objects/Object/constructor)
    2. [ ` Object.prototype.__proto__ ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) Deprecated 
  13. Methods 
    1. [ ` Object.prototype.__defineGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) Deprecated 
    2. [ ` Object.prototype.__defineSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__) Deprecated 
    3. [ ` Object.prototype.__lookupGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__) Deprecated 
    4. [ ` Object.prototype.__lookupSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__) Deprecated 
    5. [ ` Object.prototype.hasOwnProperty() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
    6. [ ` Object.prototype.isPrototypeOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
    7. [ ` Object.prototype.propertyIsEnumerable() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
    8. [ ` Object.prototype.toLocaleString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
    9. [ ` Object.prototype.toString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
    10. [ ` Object.prototype.valueOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)

##  In this article

  * Try it 
  * Syntax 
  * Description 
  * Examples 
  * Specifications 
  * Browser compatibility 
  * See also 

#  RegExp.prototype.test()

The **` test() ` ** method of [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instances executes a
search with this regular expression for a match between a regular expression
and a specified string. Returns ` true ` if there is a match; ` false `
otherwise.

JavaScript [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) objects are
**stateful** when they have the [ ` global ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global) or [ ` sticky `
](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky) flags set
(e.g., ` /foo/g ` or ` /foo/y ` ). They store a [ ` lastIndex ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) from the
previous match. Using this internally, ` test() ` can be used to iterate over
multiple matches in a string of text (with capture groups).

##  Try it

##  Syntax

js

    
    
    test(str)
    

###  Parameters

` str `

    

The string against which to match the regular expression. All values are [
coerced to strings ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) , so
omitting it or passing ` undefined ` causes ` test() ` to search for the
string ` "undefined" ` , which is rarely what you want.

###  Return value

` true ` if there is a match between the regular expression and the string `
str ` . Otherwise, ` false ` .

##  Description

Use ` test() ` whenever you want to know whether a pattern is found in a
string. ` test() ` returns a boolean, unlike the [ ` String.prototype.search()
` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search) method
(which returns the index of a match, or ` -1 ` if not found).

To get more information (but with slower execution), use the [ ` exec() `
](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method.
(This is similar to the [ ` String.prototype.match() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/match) method.)

As with ` exec() ` (or in combination with it), ` test() ` called multiple
times on the same global regular expression instance will advance past the
previous match.

##  Examples

###  Using test()

Simple example that tests if ` "hello" ` is contained at the very beginning of
a string, returning a boolean result.

js

    
    
    const str = "hello world!";
    const res