0

I have this code:

var leMessage = 'command';

var lePattern = new RegExp('command','gi');

var leBanane;
for(var i = 0; i < 10; i++) {
   leBanane = lePattern.exec(leMessage) === null ? "NULL" : "NOT NULL";
    console.log(leBanane);
}

and it outputs this:

$ node main.js                                                                                                                                            
NOT NULL                                                                                                                                                        
NULL                                                                                                                                                            
NOT NULL                                                                                                                                                        
NULL                                                                                                                                                            
NOT NULL                                                                                                                                                        
NULL                                                                                                                                                            
NOT NULL                                                                                                                                                        
NULL                                                                                                                                                            
NOT NULL                                                                                                                                                        
NULL  

Why does it return nulls? The behavior I expected was for it to return something != null since it is a match. What the hell...

PedroD
  • 5,670
  • 12
  • 46
  • 84

0 Answers0