1

In JavaScript, I have 1 variable contains int value and one having String. Now I want to append the string like pre-increment the int variable like below code I am getting error

var count = 0;
var message = "value of Variable Count by increment  is:"+ ++count;
1
  • (++count) add brackets Commented Jun 7, 2017 at 12:58

2 Answers 2

1

Wrap your counter with brackets like (++count)

var count = 0;
var message = "value of Variable Count by increment  is:" + (++count);
console.log(message);

var count = 0;
var message = "value of Variable Count by increment  is:"+ (++count);
console.log(message);
console.log("value of Variable Count by increment  is:"+ (++count));

Sign up to request clarification or add additional context in comments.

Comments

0

You can use Number as a standard function:

var count = 0;
var message = "value of Variable Count by increment  is:"+ Number(++count);
console.log(message);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.