0
When do we use ` in JavaScript?
hari: for(let i=0; i<=5; i++) { for(let j=0; j<=5; j++) { let value = prompt(`hello(${i},${j})`,''); if (!value) break hari; } } alert('done') //is there any way to use a variable in prompt?
9 Réponses
+ 3
Dev Sharma these are called backticks. You can use them instead of quotes whenever you want, they have an advantage, coz we can insert variables right within the string, unlike in quotes, where we have to close the quotes and use + to concatenate.
Both examples below would give the same output:
1) alert("Hello " + name + " you are " + age + " years old")
2) alert(`Hello ${name} you are ${age} years old`)
I prefer the second one.
+ 1
You can use this way
let value = prompt("hello"+your var name+"world");
+ 1
Dev Sharma can you give us your code attempt
+ 1
Dev Sharma i don't understand, what do you mean by "default value"?
+ 1
well, if it is a variable, and you are not using backticks, then you have to write it without quotes, so "fullname" without quotes.
+ 1
maf thanks
0
Matiyas Sirak thanks for the answer. But I didn't work.
0
Thanks maf I understood the second one but I need more clarification in the first one. In first one prompt how Javascript will recognise the default value because we are using four value in double-quotes.
Please see below
Prompt("hello "+name+"you are "+age+"year old ", "default value");
0
maf like
prompt("please enter your name", "full name");
Here full name is the default value that will appear to the visitor.