What will be printed in the console?

`var count=0;

while (count <10)

{

 console.log(count);  

 count++;

}`

1 Like

the output is 1,2,3,4,5,6,7,8,9
the last value of count is 9

2 Likes

answer
0,1,2,3,4,5,6,7,8,9

2 Likes

0 ,1,2,3,4,5,6,7,8,9

2 Likes

0 to 9 is the answer

2 Likes

I appreciate this question …
Here the while loop is mentioned with the condition of count < 10 initially count is 0. And every time the count is increasing by 1 (count++ or count = count + 1). This is good but the tricky one is it is enclosed by ``(back tick) which is a template literal the usage of this is similar to quotes(" " ) so the entire expression acts as string like “hello” or hello both acts as same…
And one more thing is the entire string was not stored in any variable so it doesn’t give any output (output : blank screen)

Additional Info:
var text = “hello”;
console.log(text); The output will be (output: hello)

but,
“hello” (output: since it is a string but we are not storing it in any variable so blank screen)

2 Likes

Here you can find more about template literals…template literals

2 Likes

Is my answer correct?

Hi @kollidayakar77 ,
you are correct, the backtick(``) symbol mostly used in JS for embedding HTML code in JS file. By using backtick you can directly write the html code in JS file.

for ex:

<script>
`<div>
<h1>This is my Heading:${heading}</h1>
</div>
`
</script>
2 Likes

Okay thanks for clarification

2 Likes