Tag: javascript

Questions Related to javascript

You work on a JavaScript project. Which of the following correctly describe the relationships of JavaScript and "objects"?

  1. JavaScript is Object-oriented

  2. JavaScript is Object-based

  3. JavaScript is Object-driven

  4. JavaScript has no relationship with objects


Correct Option: B
  1. for ( increment; initialize; test)

  2. for ( initialize; test), increment

  3. for ( initialize; test; increment)

  4. for ( test; initalize; increment)


Correct Option: C
Explanation:

To solve this question, the user needs to know the correct syntax of the FOR loop used in programming. The FOR loop is used for executing a block of code repeatedly for a fixed number of times, and it has three parts: initialization, test, and increment.

Now, let's discuss each option and explain why it is right or wrong:

A. for ( increment; initialize; test): This option is incorrect because the syntax of FOR loop starts with the initialization, followed by the test, and then the increment. In this option, the increment is mentioned first, which is not the correct order.

B. for ( initialize; test), increment: This option is incorrect because the correct syntax of the FOR loop requires three statements separated by semicolons. This option has only two statements with a comma in between, which is not the correct syntax.

C. for ( initialize; test; increment): This option is correct. The correct syntax for the FOR loop is to start with the initialization statement, followed by the test statement, and then the increment statement, all separated by semicolons. This option has all three statements in the correct order.

D. for ( test; initalize; increment): This option is incorrect because the correct syntax of the FOR loop requires the initialization statement to be mentioned before the test statement. In this option, the test statement is mentioned first, which is not the correct order.

Therefore, the answer is: C. for ( initialize; test; increment).

  1. Substring()

  2. String()

  3. Stringlength()

  4. CharAt()


Correct Option: D
Explanation:

To find out which character occurs at the 5th position in a string "How are you" in JavaScript, you can use the charAt() method.

Now, let's go through each option and explain why it is right or wrong:

A. Substring(): This option is incorrect. The substring() method is used to extract a specified part of a string and return it as a new string. It does not directly give you the character at a specific position.

B. String(): This option is incorrect. The String() function is used to convert a value to a string. It does not provide a way to access specific characters in a string.

C. Stringlength(): This option is incorrect. There is no built-in method called Stringlength() in JavaScript. This option is not relevant to the question.

D. CharAt(): This option is correct. The charAt() method is used to return the character at a specified index in a string. It takes an index as a parameter and returns the character at that index. In this case, charAt(4) will return the character at the 5th position in the string "How are you".

The Answer is: D

  1. If

  2. Ifthen

  3. Ifelse

  4. switch

  5. for


Correct Option: D
Explanation:

To solve this question, the user needs to know the different programming constructs used for branching and looping.

Option A: if statement is used for a two-way branch, where the code executes only if the condition is true. It is not used for a multi-way branch.

Option B: ifthen is not a valid programming construct.

Option C: ifelse is used for a two-way branch, where the code executes one block if the condition is true and another block if the condition is false. It is not used for a multi-way branch.

Option D: switch statement is used for a multi-way branch, where the code executes different blocks of code based on different possible values of an expression.

Option E: for loop is used for repeating a block of code for a specific number of times or for iterating over a collection of items. It is not used for branching.

Therefore, the correct answer is:

The Answer is: D. switch

  1. Check for the presence of certain characters

  2. Check the position of substrings

  3. Test the length of data

  4. Check the variable type of the strings

  5. Either ABC


Correct Option: E

Which of the following is the minimum browser version that supports JavaScript

  1. Navigator v2.0

  2. Mozilla V1.5

  3. IE 2.0

  4. Navigator V1.0


Correct Option: A
  1. When you have multiple statements on multiple lines

  2. When you have multiple statements on a line

  3. When you have single statement on multiple lines

  4. When you have single statement on a line


Correct Option: B
  1. Version 1.2

  2. Version 1.1

  3. Version 1.3

  4. Version 1.4

  5. All of the above


Correct Option: E