0% found this document useful (0 votes)
2 views

javascript section - 3

The document explains various concepts related to operators in JavaScript, including their types, precedence, and associativity. It also covers specific operators like arithmetic, comparison, logical, assignment, and ternary operators, as well as methods for user interaction such as alert(), prompt(), and confirm(). Additionally, it provides examples and explanations of how these operators and methods function within JavaScript programming.

Uploaded by

Sreehari Rajesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

javascript section - 3

The document explains various concepts related to operators in JavaScript, including their types, precedence, and associativity. It also covers specific operators like arithmetic, comparison, logical, assignment, and ternary operators, as well as methods for user interaction such as alert(), prompt(), and confirm(). Additionally, it provides examples and explanations of how these operators and methods function within JavaScript programming.

Uploaded by

Sreehari Rajesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

23. What is an operator?

Answer – In computer programming, an operator is a symbol that often


denotes an action or process. These symbols were modified from logic and
mathematics. A specific value or operand can be manipulated by an operator.

24. What is the associativity of an operator?


Answer – The operator associativity has an impact on the evaluation of
expressions as well. Associativity refers to the direction that the full phrase is
evaluated (from right to left or from left to right).

25. What is an precedence of operator.


Answer – An operator’s precedence determines how “tightly” it binds two
phrases together. Because the multiplication (“*”) operator has priority over
the addition (“+”) operator, the result to the formula 1 + 5 * 3 is 16 and not 18,
for instance. If necessary, parentheses can be used to enforce precedence.

26. What are the major types of operators supported by JavaScript?


Answer – The major types of operators supported by JavaScript are –
a. Arithmetic Operators
b. Comparison Operators
c. Logical Operators
d. Assignment Operators
e. Ternary Operators

27. What would be the result of 1+2+“3” in JavaScript?


Answer – Result will be 33

28. What is the difference in the outputs that you get when you use the
following operators =; == ; and ===.
Answer –
a. The assignment operator equal to (=) changes the value of the expression
on its right to that of the variable to the left of the equal sign.
b. A comparison operator called double equals (==) changes operands of the
same type before comparison.
c. In JavaScript, the stringent equality comparison operator === (Triple
equals) returns false for values that are not of the same type. With this
operator, type casting is done for equality. It will give a false result if we
compare 2 with “2” using the comparison operator ===.

29. Explain what you understand by Modulo operator.


Answer – The modulus operator, which operates between two accessible
operands, is an addition to the JavaScript arithmetic operators. To obtain a
result, it divides the supplied numerator by the supplied denominator. To put it
another way, it results in an integer division remainder. As a result, the leftover
amount is likewise always an integer. example 10%2 the result will be 5;
30. What is conditional operator?
Answer – Ternary operator is also known as conditional operator. The ternary
operator (?:) is used to express a condition (it takes three operands). The first
operand is implicitly changed to boolean by the conditional operator.

31. What is a dialog box?


Answer – The dialogue box is a graphical control element that looks like a
small window and gives the user information and asks for a response. There
are three types of dialogue boxes used by JavaScript: ALERT, PROMPT, and
CONFIRM.

32. What is Window object?


Answer – All browsers support the window object. It symbolizes the window
of the browser. All variables, functions, and objects that are global to
JavaScript are immediately added as members of the window object. The
window object’s characteristics include global variables. The window object’s
methods are known as global functions.

33. What is alert() method?


Answer – The alert() method shows an alert box with an OK button and a
message. When you want the user to get information, you utilise the alert()
method.

34. What is prompt() method?


Answer – The user is prompted for input in a dialogue box by the prompt()
method. If the user selects “OK,” the prompt() method returns the input value;
otherwise, it returns null.

35. What is confirm method()?


Answer – A modal dialogue with an optional message and the buttons OK
and Cancel is displayed using the confirm() method. If the user hits “OK,” it
returns true; if not, it returns false. Until the box is closed, the user is unable to
view other areas of the page.

36. What happens when a user clicks the cancel button of the prompt
dialog box?
Answer – If the user clicks the Cancel button, prompt( ) returns null.

37. What is the difference between confirm and alert method?


Answer – If we want the user to receive the information, we utilize an alert
box. If we want the user to confirm or approve something, we use the confirm
box.
38. Create a JavaScript program that prompts the user for a phone
number and then asks the user for confirmation.
Answer –

<html>

<script>

var phoneno;

phoneno=confirm("Please Confirm" + prompt("Enter Phone Number"));

</script>

</html>

39. Write a program to ask the user to input two values and then perform
the arithmetic operation and display the result.

<html>

<script>

var num1,num2,sum;

num1=parseInt(prompt("Enter Number"));

num2=parseInt(prompt("Enter Number"));

sum=num1+num2;

document.write("Sum is " + sum);

</script>

</html>

Q. What will be the output of the following codes

2* 3 3 * -2 false * 5 true * 3 5 * "foo" Infinity * 0 Infinity * Infinity

Q.6: What will be the output of the following codes 2 - 3 3 - 2 false - 5 true + 3 5 + "foo"
Q.8: What is the difference in the outputs that you get when you use the following operators =; == ;
and ===.

Q.9: explain what you understand by Modulo operator.

Q.10: specify four types of operators that can be used in JavaScript.

Q.11: explain what a logical not operator does using some examples.

Q.12: What is conditional operator?

Q.13: Fill in the blanks

(a) if x = 24 and y = 3 then the output of x*=x/y is ............................ .

(b) if x = 25 and y =3 then the output of x+=y is ............................ .

(c) , ............................ and ............................ are all logical operators used in JavaScript

(d) if x = 14 and y = 3 then the output of x mod y is ............................ .

(e) if x = 15 and y =3 then the output of x%y is ............................ .

(f) Plus sign is used to ............................ numbers and strings.

(g) When i want to display an alert which says ‘Welcome’ and then the name of the student, i will
have the use the ............................ operator.

You might also like