Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
78 views
in Technique[技术] by (71.8m points)

How do I output a string or number in JavaScript using format specifier?

var b=4; //variable
document.write("The value  of b is %d", b);

In Java, it would be:

int b;`
System.out.printf("the value of b is %d", b);
question from:https://stackoverflow.com/questions/65919832/how-do-i-output-a-string-or-number-in-javascript-using-format-specifier

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try doing this:

let b = 4;

let valueString = `The value of B is: ${b}`

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...