Why does question makr means in a object

so today I spend good time to debug my copy paste from word document but failed of why object key was ‘question’ and value was ‘answer’
image

	'items' : [
		{
			'question': 'How it works',?
			'answer': html`
				<p>Agree with Terms and conditions to see, how</p>
			`
		},

I found the issue with help of someone but fail to understand why ? (question mark) outside a speech mark made the value = answer.

The code you posted should just be a syntax error.

But if you remove the comma that separates the object properties it becomes a ternary that evaluates the string 'How it works' which is a truthy value so the “key” of what should have been the next object property becomes the evaluated value of the expression.

const test = {
  'question': 'How it works' ? 'if true' : 'if false'
}

console.log(test); // { question: 'if true' }

const test2 = {
  'question': false ? 'if true' : 'if false'
}

console.log(test2); // { question: 'if false' }

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.