CKTIS / JavaScript
HTMLOptionElement — option value
HTMLOptionElement represents an option element. Its value property returns the value of the value attribute if present, or a value derived from the option's text if the attribute is absent. The current selection state does not affect the result.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
new Option(text, value, defaultSelected, selected)
option.value
option.value = "code"HTMLOptionElement is the DOM interface for an option element and inherits from HTMLElement. Option value here means the option.value property, not a separate interface. This is a browser Web API, not an ECMAScript language feature; having Node 24 does not establish availability. MDN marks the interface and value as widely available across browsers since July 2015.
value returns a string from the value attribute. When that attribute is absent, the value comes from the option's text. An explicit value="" produces an empty string instead of the fallback. Separate a data code such as "js" from the text "JavaScript": assigning to option.value sets the attribute value without changing the label.
new Option(text, value, defaultSelected, selected) creates an option; all arguments are optional. text defaults to "", and omitting value allows the text to supply the value. defaultSelected reflects the selected attribute, whereas selected describes current selection. Both boolean arguments default to false; do not treat them as interchangeable.
The example creates a standalone option, changes its value without changing its text, then removes the value attribute to demonstrate the text fallback. The four expected lines are recorded in output.
Examples
const option = new Option("JavaScript", "js", false, true);
console.log(`${option.text}|${option.value}`);
console.log(`${option.defaultSelected}|${option.selected}`);
option.value = "javascript";
console.log(`${option.text}|${option.value}`);
option.removeAttribute("value");
console.log(option.value);Result
JavaScript|js false|true JavaScript|javascript JavaScript
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.