Q. A _________ is a group of reusable code which can be called anywhere in your program.

  • (A) switch
  • (B) loop
  • (C) function
  • (D) exception
πŸ’¬ Discuss
βœ… Correct Answer: (C) function

Q. The most common way to define a function in JavaScript is by using the ____________ keyword.

  • (A) define
  • (B) function
  • (C) var
  • (D) fun
πŸ’¬ Discuss
βœ… Correct Answer: (B) function

Q. Which statement required if you want to return a value from a function?

  • (A) return
  • (B) loop
  • (C) break
  • (D) continue
πŸ’¬ Discuss
βœ… Correct Answer: (A) return

Q. The Function() constructor expects ______ number of string arguments

  • (A) 0
  • (B) 1
  • (C) 2
  • (D) any
πŸ’¬ Discuss
βœ… Correct Answer: (D) any

Q. Which among the following regular expression specifies that password should contain at least one capital letter or one digit.

  • (A) /.*[A-Z].*/.test(password) && /.*[0-9].*/.test(password)
  • (B) /.*[A-Z].*/.test(password) || /.*[0-9].*/.test(password)
  • (C) /.*[A-Z][0-9].*/.test(password)
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) /.*[A-Z].*/.test(password) || /.*[0-9].*/.test(password)

Q. Which of the following string will match the RegEx "((d).(dd))$"?

  • (A) 2.2
  • (B) 223.12
  • (C) 22.123
  • (D) 223.123
πŸ’¬ Discuss
βœ… Correct Answer: (B) 223.12

Q. Consider the following JavaScript statement containing regular expressions and check if the pattern matches?

Code:
var text = "lestfindcourse: 1, 2, 3";
var pattern = /d+/g;
  • (A) pattern.test(text)
  • (B) text.test(pattern)
  • (C) text.equals(pattern)
  • (D) text==pattern
πŸ’¬ Discuss
βœ… Correct Answer: (A) pattern.test(text)

Q. The regular expression to match any one character not between the brackets is __________

  • (A) [\D]
  • (B) [^...]
  • (C) [^]
  • (D) [....]
πŸ’¬ Discuss
βœ… Correct Answer: (B) [^...]
Explanation:

In regular expressions, [^...] matches any one character that is not listed inside the brackets.

  • The ^ at the beginning inside [] negates the character set.

Example:

let regex = /[^abc]/;
console.log(regex.test('d')); // true (because 'd' is not 'a', 'b', or 'c')

Q. What would be the result of the following statement in JavaScript using regular expression methods?

  • (A) Throws an exception
  • (B) Returns [1,2,3,4,5,6,7,8,9]
  • (C) Returns ["123","456","789"]
  • (D) Returns ["123""456""789"]
πŸ’¬ Discuss
βœ… Correct Answer: (C) Returns ["123","456","789"]

Q. What will be the output of the following JavaScript code?

Code:
System.out.println( Pattern.matches("[lfc]", "lets") );
  • (A) l
  • (B) true
  • (C) false
  • (D) undefined
πŸ’¬ Discuss
βœ… Correct Answer: (C) false