What Will Be The Purpose Of Exec In The Following Javascript #205
What will be the purpose of exec() in the following JavaScript code?</p> <pre><code class="language-javascript"> var pattern = /Java/g; var text = "JavaScript is more fun than Java!"; var result; while ((result = pattern.exec(text)) != null) { alert("Matched '" + result[0] + "'" +" at position " + result.index +"; next search begins at " + pattern.lastIndex); } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs106 Javascript. It can also be found in gs gs106 Classes and Modules - JavaScript Pattern Matching and Regular Expressions - Quiz No.1.
What will be the purpose of exec() in the following JavaScript code?
var pattern = /Java/g; var text = "JavaScript is more fun than Java!"; var result; while ((result = pattern.exec(text)) != null) { alert("Matched '" + result[0] + "'" +" at position " + result.index +"; next search begins at " + pattern.lastIndex); }
Returns the same kind of array whether or not the regular expression has the global g flag
Returns different arrays in the different turns of iterations
Return a sub part of the array
Returns a null value
Similar question(s) are as followings:
Online Quizzes of gs106 Javascript
Graphics and Rendering in JavaScript - Scripted Media - Quiz No.1
gs gs106 Javascript
Online Quizzes