Write the output of the following JavaScript statements :(i) document.write(1 + ‘‘2’’ + ‘‘2’’);(ii) document.write(‘‘1’’ + ‘‘2’’ + ‘‘2’’);
Question
Write the output of the following JavaScript statements :(i) document.write(1 + ‘‘2’’ + ‘‘2’’);(ii) document.write(‘‘1’’ + ‘‘2’’ + ‘‘2’’);
Solution
(i) The output of the JavaScript statement document.write(1 + ''2'' + ''2''); will be 122. This is because JavaScript performs type coercion in such a way that it converts the number 1 into a string when it sees that the other operands are strings. So, it concatenates the strings together resulting in 122.
(ii) The output of the JavaScript statement document.write(''1'' + ''2'' + ''2''); will be 122. In this case, all the operands are strings, so JavaScript simply concatenates them together resulting in 122.
Similar Questions
What is the correct JavaScript syntax to write "Hello World"?Question 9Select one:a.document.write("Hello World")b.System.out.println("Hello World")c.println ("Hello World")d.response.write("Hello World")
What will be the output of the following code snippet?`<script type="text/javascript" language="javascript">` var a = "Synoverge";var result = a.substring(2, 4);document.write(result); `</script>`noSelect one:a. Synovergeb. noc. noved. vergeClear my choice
Which of the following is the correct output for the following JavaScript code:var x=3; var y=2; var z=0; If(x==y) document.write(x); elseif(x==y) document.write(x); else document.write(z); Question 3Select one:a.3b.0c.2d.Error
Write the output of the following JavaScript code (Justify youranswer) :(i) var x =10;function function1(){ var x=20; }functionl();alert(x);(ii) x =10;function functionl(){ x=20; }functionl();alert(x);
28. What is the output of the following JavaScript code?*var fruits = [“apple”, “banana”, “cherry”];var result = fruits.join(” – “);console.log(result);
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.