Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:46:12+00:00 2026-06-18T05:46:12+00:00

</!DOCTYPE html> </html> </body> <p>Given that y=5, calculate x=++y, and display the result.</p> <button

  • 0
  </!DOCTYPE html>
</html>
</body>

<p>Given that y=5, calculate x=++y, and display the result.</p>
<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction()
{
var y=5;
var x=++y;
var demoP=document.getElementById("demo")
demoP.innerHTML="x=" + x + ", y=" + y;
}
</script>

<p><strong>Note:</strong> Both variables, x and y, are affected.</p>
</body>
</html>*/

Clearly, I’m a beginner but I have no one else to ask. It would be helpful if someone could explain the reason behind demop.innerHTML="x=" + x + ", y=" +y; in this code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:46:14+00:00Added an answer on June 18, 2026 at 5:46 am

    it would be helpful if someone could explain the reason behind demop.innerHTML=”x=” + x + “, y=” +y; in this code

    That line of code doesn’t increment anything, in that line the + is a string concatenation operator, not a number addition operator. It’s used for building up a string (it doesn’t change x or y), which is then assigned to demoP.innerHTML, which replaces the content of the DOM element with that string’s contents.

    The line that’s a bit harder to understand for a beginner is this one:

    var x=++y;
    

    That does three things:

    1. It declares a variable called x in the current scope (var).

    2. It increments the value of y.

    3. It assigns the incremented value to x.

    So both x and y end up with 6, since the increment happens before the value of y is used to initialize x. This is called a “prefix increment”. “Pre” because it happens before we use the value for something.

    Like most languages that derive their main syntax from B (so, C, C++, Java, C#, JavaScript, and many others), there’s also a “postfix” increment:

    var x = y++;
    

    “Post” because we increment after using the value. If the line were as above, x would get 5 (y‘s old value) and y would get 6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HTML <!doctype html> <html> <head> </head> <body> <button id=b1 type=button>Show Spoiler</button> <p id=p1 style=display:none>
<!DOCTYPE HTML> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.2.js></script> <script type=text/javascript> $(#myBtn).on(click,function(){ alert('myBtn Clicked'); }); </script>
I have a HTML code with the java Script given below. <!DOCTYPE html> <html>
Given the following page that includes an iframe <!DOCTYPE html> <html> <head> <link rel=stylesheet
Given the following HTML: <!DOCTYPE html> <html> <body> <div id=container> <div id=left style=float: left;
Given the following HTML: <!doctype html> <html> <body> <span style=background-color: blue;> Some text here
<!DOCTYPE HTML> <html> <body> <video width=320 height=240 controls=controls> <source src=tutorial.mp4 type=video/mp4 /> Your browser
I have the following html and css code: <!DOCTYPE HTML> <html> <head> </head> <body>
See example: <!DOCTYPE html> <html> <head> <title>language</title> <script type=text/javascript src=http://www.google.com/jsapi> </script> </head> <body> <div
i am trying to understand following fragment of javascript code <!DOCTYPE html> <html> <body>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.