Contents:
a. The …………………… box is used to display information to the user.
ans: message
b. A …………………… is a storage area where value is stored and retrieved when required.
ans: variable
c. The …………………… operator finds out the remainder.
ans: modulus
d. The …………………… operator is a unary operator.
ans: !NOT
e. The …………………… operator uses ? (question mark) and : (colon) characters.
ans: conditional
a. The semicolon at the end of simple statements in JavaScript is mandatory.
ans: True
b. In JavaScript MARKS and marks are treated as the same variable.
ans: False
c. A simple statement must be enclosed in braces.
ans: False
d. A compound statement consists of several instructions grouped in a block.
ans: True
e. The switch statement can only be used to compare an expression against constants.
ans: True
a. Which one is an invalid variable name in JavaScript?
i.1employeename
ii. Employeename
iii. Employee_Name
iv. EmployeeName
ans: i.1employeename
b. A block of statements is enclosed within
i. ( )
ii.{ }
iii.[]
iv. ” ”
ans: ii.{ }
c. The statement used to exit from the switch…case statement is
i. goto
ii. break
iii. continue
iv. exit
ans: ii. break
d. …………………… takes a number as input from the user.
i. Alert message
ii.prompt dialog box
iii. Confirm dialog box
iv. All of these
ans: ii.prompt dialog box
e. Which one of these is not an arithmetic operator in JavaScript?
i. *
ii.^
iii.+
iv. /
ans: ii.^
f. == is a/an
i. Arithmetic operator
ii. relational operator
iii. Compound Assignment operator
iv. Logical operator
ans: ii. relational operator
a. What are the three data types in JavaScript?
ans: The three types of data types in JavaScript are:
(a) Numbers Eg. 453, 98.12, etc.
(b) Strings Eg. “Python Programming”, “grade”, etc.
(c) Boolean Eg. True or False
b. How will you declare variables subl, sub2, and sub3 in JavaScript?
ans: In JavaScript, when we are declaring a variable, we start with the letters ‘var’. After a space, we then need to write the variable name.
Therefore, we will declare variables sub1, sub2, and sub3 as:
var sub1, sub2, sub3
c. Name the different forms of if statement.
ans: if statement has the following formats – if, if…..else and if….else if.
d. Name the three logical operators.
ans: JavaScript supports three logical operators. &&(AND), || (OR) and !!(NOT)
e. Write the statements equivalent to A++ and A— —.
ans: The statements equivalent to A++ is increment operator and A– is decrement operator.
f. Write the shorthand form for the following:
A = A + 15
B = B +=1
ans: A=A+15
B=B+=15
a. Explain the two types of comments in JavaScript.
ans: • Single line comment It starts with a pair of slash sign (//). The browser ignores anything from the pair of slash sign (//) till the end of that same line. For example:
// Single line comment
• Multi-line comment This is also known as block comment. It includes more than one line between /* and */ characters: The browser ignores the statements between these characters. For example:
/* This is a block comment */
b. What are the rules for naming a JavaScript variable?
ans: Rules for. Naming a Variable are
• The name must begin with a letter or the underscore character. It should not start with a digit. The first character is followed by letters, digits, or underscore sign.
• It should not be a reserved word.
• We cannot have spaces in a variable name.
• JavaScript is case sensitive. Thus, for example, name, NAME, and Name are treated as three different variables.
c. What are the limitations of switch statement?
ans: The switch statement can only be used to compare an expression against constants. Therefore,
• The case label cannot be a variable. For example, case n: where n is a variable.
• The case label cannot be a range. For example, case (1..3):. This is not a valid constant.
d. What is the difference between simple and compound statements?
ans:
| Simple Statements | Compound Statements |
1. | A simple statement consists of a single instruction. | A compound statement consists of several instructions grouped in a block |
2. | It doesn’t require braces to enclose it. | Such statements must be enclosed in braces if we wish to treat them all as a single statement. |
e. Explain the working of conditional operator with an example.
ans: The conditional operator evaluates an expression and returns the value written after ‘?’ if the condition evaluated is true. In case the result is false, the value after ‘:’ is returned. Its general format is:
var result = condition ? “TRUE”.: “FALSE”;
To understand the concept of this operator, we do the following:
1. Type the following JavaScript code in Notepad and save it as .html file.
<!DOCTYPE html>
<html>
<body>
<script language=”javascript” type=”text/javascript”>
var age, result
age = 20,a,
result = age > 18 ? “You are over 18 years” : “You are below or equal to 18 years”
document.write(result)
</script>
</body>
</html>
2. Open the HTML file in Internet Explorer. The output will appear as ‘You are over 18 years’.
1. Jasmine has written the given code to display a message box on the screen, but the message box is not showing on the screen. Find the problem in this code and rewrite it to display the given statement in a message box.
ans: The correct code for the above question is:
2.Rewrite the following code using if…else if statement.
ans:
if (x==”N”) {
document.write (“North”)
}
else if (x==”E”) {
document.write (“East”)
}
else if (x==”W”) {
document.write (“West”)
}
else if (x==”S”) {
document.write (“South”)
}
else{
document.write (“Enter correct Code”)
}
</script>
</body>
</html>
3. What will be the output of the following code:
ans: a=16
b=14
4. Evaluate the following arithmetic expression and find out its output, assuming b = 4 and c = 4.
a=b*3/ 4+c/ 4+8—b +5/8
ans:
Code:Output: a=8.625
5. Assuming A=5 and B=6, what will be the result of the following statements:
i. ((A != B) && (A >= B))
ii. ((A != B) || (A <= B))
iii. !(A > B)
ans:
i. Code:
Output: false
ii. Code:
Output: true
iii. Code:
Output: true
6. Write the following if…else statement using the conditional operator.
if (x == 100)
a = “x is 100”
else
a = “x is not 100”
ans:
Marketing is a multifaceted discipline, often categorized into various specialized areas to achieve specific goals.…
In today’s fast-paced business landscape, efficient document management is critical for success. Traditional methods of…
Duplicate and plagiarized content works like a Trojan horse. You think it's a blessing, but…
In today’s fast-paced and dynamic social media environment, having a social media account with high…
In the early days of the web, static websites were common. They presented repetitive material,…
Are you ready to publish your work online? Wait a second! Is your content unique…
View Comments
It helped me a lot tq .... But if I could download it as pdf it would be better ... tq
Thank you so much... yes we are thinking of that as well. For further information you can contact us at support@ujudebug.com
Pdf file is needed