I am studying about RegExp but everywhere I can see two syntax
The key difference is that literal REGEX can't accept dynamic input, i.e. from variables, whereas the constructor can, because the pattern is specified as a string.
Say you wanted to match a number of words, which came from an array:
var words = ['foo', 'bar', 'orange', 'platypus']; var str = "Foo something nice orange what a lovely platypus"; str.match(new RegExp('\\b('+words.join('|')+')\\b'));
This would not be possible with a literal