1.
Given x = new Date(), how do you represent x as a String in universal time (time zone +0000)?
Correct Answer
C. X.toUTCString();
Explanation
The correct answer is x.toUTCString() because the toUTCString() method converts the date to a string representation in universal time (time zone +0000). This method returns a string that represents the date and time in the format "Thu, 01 Jan 1970 00:00:00 GMT".
2.
Where the < script > tag can be used
Correct Answer
C. Both < head > and < body > tags
Explanation
The tag can be used in both the and tags of an HTML document. Placing it in the tag allows the script to be loaded and executed before the content of the webpage is displayed. This is useful for scripts that need to be run before the page is rendered. On the other hand, placing the tag in the tag allows the script to be loaded and executed after the content of the webpage is displayed. This is useful for scripts that manipulate or interact with the content of the webpage.
3.
What does JSON stand for?
Correct Answer
B. JavaScript Object Notation
Explanation
JSON stands for JavaScript Object Notation. It is a lightweight data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. It is primarily used to transmit data between a server and web application, as an alternative to XML. JSON uses key-value pairs and supports arrays, making it a popular choice for representing structured data.
4.
Given the following, what is the value of x?
var x = typeof "abc";
Correct Answer
B. String
Explanation
The value of x is "string" because the typeof operator returns the data type of a variable or expression. In this case, "abc" is a string, so the typeof "abc" is "string".
5.
Variable x has a value of 5. Variable y has a value of 7
x < 7 && y > 6
Correct Answer
A. True
Explanation
The expression "x < 7 && y > 6" is evaluating two conditions using logical AND operator. The first condition "x < 7" is true because the value of x is 5 which is less than 7. The second condition "y > 6" is also true because the value of y is 7 which is greater than 6. Since both conditions are true, the overall expression evaluates to true. Therefore, the correct answer is True.
6.
Is javascript case sensitive ?
Correct Answer
A. True
Explanation
JavaScript is indeed case sensitive. This means that it distinguishes between uppercase and lowercase letters. For example, "variable" and "Variable" would be considered as two different variables in JavaScript. This is important to keep in mind when writing code, as using incorrect casing can lead to errors or unexpected behavior in the program.
7.
To convert string to number, which function do we use ?
Correct Answer
C. ParseInt
Explanation
The parseInt function is used to convert a string to an integer number. It parses the string and returns an integer value. This function is commonly used when we need to perform mathematical operations or comparisons on a string that represents a number.
8.
In javascript, is it required having semi-colon " ; " at the end of the statement ?
Correct Answer
B. False
Explanation
In JavaScript, it is not required to have a semi-colon at the end of every statement. JavaScript has automatic semi-colon insertion, which means that the interpreter will insert a semi-colon at the end of a statement if it is missing. However, it is considered a best practice to include semi-colons in order to avoid potential issues and make the code more readable.
9.
How do you check what the type of a value in variable x is?
Correct Answer
B. Typeof(x)
Explanation
The typeof() function is used to check the type of a value in JavaScript. In this case, typeof(x) would return the type of the value stored in the variable x. The other options, gettype(x), Object.type(x), and x.type, are not valid JavaScript syntax for checking the type of a value.
10.
What is the value of the following express: 8 % 3
Correct Answer
B. 2
Explanation
The expression 8 % 3 calculates the remainder when 8 is divided by 3. In this case, 8 divided by 3 is equal to 2 with a remainder of 2. Therefore, the value of the expression is 2.
11.
You need to update the content of a <div> using the following code, complete the missing part
<div id="myDiv"></div>
<script>
document.getElementById('myDiv').MISSING_PART = "new content"
</script>
Correct Answer
D. InnerHTML
Explanation
The missing part in the code should be "innerHTML". The correct code should be:
document.getElementById('myDiv').innerHTML = "new content"
This code will update the content of the element with the id "myDiv" by setting its innerHTML property to "new content".
12.
What's the output of the following code
var name = 'John',
age = 20
console.log(`Hi, my name is ${name.toUpperCase()} and I'm ${++age} years old`)
Correct Answer
D. Hi, my name is JOHN and I'm 21 years old
Explanation
The code uses template literals to concatenate the variables `name` and `age` into a string. `name.toUpperCase()` converts the value of `name` to uppercase, resulting in "JOHN". `++age` increments the value of `age` by 1, resulting in 21. Therefore, the output is "Hi, my name is JOHN and I'm 21 years old".
13.
How to access the current element using DOM
<input type="radio" name="gender" value="Male">
Correct Answer
C. Document.getElementsByName
Explanation
The correct answer is document.getElementsByName. This method allows you to access elements by their name attribute. In this case, if you want to access the current element of the radio buttons with the name "gender", you can use this method to retrieve all the elements with that name and then loop through them to find the current one.
14.
Which of these is not a logical operator?
Correct Answer
B. &
Explanation
The correct answer is "&". The logical operators in programming are used to perform logical operations on boolean values. The "!" operator is the logical NOT operator, which negates the value of a boolean expression. The "&" operator is the bitwise AND operator, not a logical operator. The "&&" operator is the logical AND operator, which returns true if both operands are true. The "||" operator is the logical OR operator, which returns true if at least one of the operands is true.
15.
What is the value of the variable a?
var a = "cat".length * 2;
Correct Answer
B. 6
Explanation
The value of the variable "a" is 6. This is because the expression "cat".length returns the length of the string "cat", which is 3. Multiplying 3 by 2 gives us the value of 6 for the variable "a".
16.
What is the value of x ?
var a = false;
var x = a ? “A” : “B”;
Correct Answer
D. "B"
Explanation
The value of x is "B" because the variable a is assigned the value false. In the ternary operator, if the condition (a) is true, the value "A" is assigned to x, but if the condition is false, the value "B" is assigned to x. Since a is false, the value "B" is assigned to x.
17.
How would one declare a string variable?
Correct Answer
D. Any of these
Explanation
The correct answer is "Any of these" because all three options demonstrate valid ways to declare a string variable in JavaScript. The first option assigns a string value directly to the variable "name", the second option assigns a string value to the variable "names", and the third option creates a new String object with the value "John" and assigns it to the variable "firstname". Therefore, any of these options can be used to declare a string variable.
18.
Dvising a number by zero in JavaScript returns
Correct Answer
C. Infinity
Explanation
When dividing a number by zero in JavaScript, it returns "Infinity". This is because dividing any number by zero is mathematically undefined and considered to be an infinitely large value. Therefore, JavaScript represents this result as "Infinity" to indicate that the division operation is not possible and the result is an infinitely large value.
19.
How do you round the number 11.25, to the nearest whole number?
Correct Answer
A. Math.round
Explanation
To round the number 11.25 to the nearest whole number, you can use the Math.round function. This function rounds a number to the nearest integer. In this case, 11.25 is closer to 11 than to 12, so Math.round(11.25) will return 11.
20.
What is the value of "b"
var a = "A";
var b = a.concat("B");
Correct Answer
B. "AB"
Explanation
The value of "b" is "AB" because the concat() method is used to concatenate two strings together. In this case, the variable "a" is the string "A" and "B" is being concatenated to it, resulting in the string "AB".
21.
Which event fires whenever a control loses focus?
Correct Answer
D. On blur
Explanation
The "on blur" event fires whenever a control loses focus. This means that when a user clicks outside of the control or tabs to another element, the "on blur" event will be triggered. This event is commonly used to perform actions or validations when the user finishes interacting with a specific control, such as saving the entered data or checking for input errors.
22.
Which of the following is the equivalent of the following snippet
if (a) { x = b; } else { x = c; }
Correct Answer
B. X = a ? b : c
Explanation
The correct answer is "x = a ? b : c". This is the equivalent of the given snippet because it uses the ternary operator "? :" which is a shorthand for an if-else statement. It checks the condition "a", and if it is true, assigns the value of "b" to "x", otherwise assigns the value of "c" to "x".
23.
Which of the following events is used to handle the user click action
Correct Answer
C. Onclick
Explanation
The event "onclick" is used to handle the user click action. This event is triggered when the user clicks on an element, such as a button or a link, on a webpage. It allows developers to define a specific action or behavior to be executed when the user interacts with that element by clicking on it.
24.
Which message does the following log to the console?
bar();
function bar() { console.log('bar'); }
Correct Answer
D. "bar"
Explanation
The message that is logged to the console is "bar". This is because the function bar is called before it is defined, which is allowed in JavaScript. So when the function is called, it logs the string "bar" to the console.
25.
What is the value of x?
var x = '1'+2+3;
Correct Answer
C. "123"
Explanation
The value of x is "123" because the expression is evaluated from left to right. The first operand is a string "1", so the following operands are concatenated as strings. Therefore, 2 and 3 are also treated as strings and concatenated to "1" to form "123".
26.
You have to change the background color of the page programmatically, which of the following instructions is correct ?
Correct Answer
C. Document.body.style.background = 'red'
Explanation
The correct answer is document.body.style.background = 'red'. This is because the style property allows you to access and modify the CSS properties of an element, including the background color. By setting the background property to 'red', you can change the background color of the page programmatically. The other options are incorrect because they either modify the wrong property (body.background, body.color) or use the wrong syntax (missing the style property).
27.
What is the value of variable a
var a = 3; var b = 2; var c = a; var a = b = c = 1;
Correct Answer
C. 1
Explanation
The value of variable a is 1 because the code assigns the value of 1 to variables b, c, and a in that order. Therefore, the final value assigned to variable a is 1.
28.
What is the value of the variable foo ?
var foo = 10 + parseInt("20 bar 30");
Correct Answer
A. 30
Explanation
The value of the variable foo is 30. In the given code, the parseInt() function is used to convert the string "20 bar 30" into an integer. However, since the string contains non-numeric characters, the parseInt() function will only consider the numeric characters at the beginning of the string. Therefore, it will convert "20" into the number 20. The addition operation then adds 10 to 20, resulting in 30.
29.
What would the code below return
Math.min() < Math.max()
Correct Answer
B. False
Explanation
The code is comparing the result of the Math.min() function with the result of the Math.max() function. Since no arguments are provided to these functions, they will return positive or negative infinity. In JavaScript, positive infinity is greater than negative infinity, so the comparison Math.min() < Math.max() will evaluate to false. Therefore, the code will return false.
30.
Evaluate the following:
undefined + 2
Correct Answer
B. NaN
Explanation
When you try to perform addition with undefined and a number (in this case, 2), JavaScript treats undefined as NaN (Not a Number). Therefore, the result of undefined + 2 is NaN.
31.
Within innerHTML, can you create HTML markup content and append it to the page
Correct Answer
A. Yes
Explanation
Yes, within innerHTML, you can create HTML markup content and append it to the page. The innerHTML property allows you to manipulate the HTML content of an element. By setting the innerHTML property of an element, you can add HTML markup content, such as tags, attributes, and text, to that element. This allows you to dynamically generate and insert HTML content into the page.
32.
To get value from user input we use which box ?
Correct Answer
B. Prompt
Explanation
The correct answer is "Prompt" because the prompt box is used to get a value from the user. It displays a dialog box with a message and an input field where the user can enter a value. This value can then be used in the program for further processing or manipulation. The other options, Confirm and Alert, are used for displaying messages to the user but do not allow for user input. "None of the above" is not the correct answer as the prompt box is specifically designed for getting user input.
33.
In do-while .. while with condition required ';' at the end of ()
Correct Answer
B. False
Explanation
In a do-while loop, the condition is placed inside the parentheses after the keyword "while". It does not require a semicolon at the end of the parentheses. Therefore, the statement "In do-while .. while with condition required ';' at the end of ()" is false.
34.
Where do we start a javascript code ?
Correct Answer
C. In the < script > tag
Explanation
In JavaScript, we start the code by writing it within the tag. This tag is used to define a client-side script, and it is placed within the HTML document. The JavaScript code written within the tag will be executed by the browser when the webpage loads. The other options mentioned, such as tag and tag, are not valid for starting a JavaScript code.