Aheho
Aheho

Reputation: 12821

What does the / operator do in javascript besides division

I'm using an open source javascript library and found some bugs in it's behavior. I decided to look through the source to see if I can edit it to correct the issues I've found.

It littered with code constructs that I don't understand. For instance:

if (/pop/i.test(settings.tipAnimation)) {
       // blah 
       // blah
}

What does "/pop" refer to? I don't even see any object properties named pop. And I've never seen the forward slash notation.

Upvotes: 1

Views: 62

Answers (1)

Justin Niessner
Justin Niessner

Reputation: 245429

That would define a Regular Expression using a Regular Expression Literal.

Programmer's Guide to Regular Expressions

It would be the equivalent of the following object instantiation:

var regex = new RegEx("pop","i");
if(regex.test(settings.tipAnimation)){
    // blah
}

Upvotes: 5

Related Questions