ValueQ

ValueQ[expr]

gives True if a value has been defined for expr, and gives False otherwise.

Details and Options

  • ValueQ has attribute HoldAll.
  • ValueQ[expr,Methodm] uses the specified method to determine if the expression has a value defined for it.
  • Possible values for the option Method include:
  • Automaticautomatic behavior
    "SymbolDefinitionsPresent"one or more symbols have any sort of definition present
    "TrialEvaluation"test if the expression changes after evaluation
    "OwnValuesPresent"one or more symbols have a non-empty OwnValues
    "Legacy"match behavior in Version 12.1 and earlier
  • With the default method, Automatic, ValueQ[expr] effectively uses "OwnValuesPresent" if expr is a symbol and "SymbolDefinitionsPresent" for most other expressions.

Examples

open allclose all

Basic Examples  (2)

No value has been assigned to the variable x:

Assign a value:

Now ValueQ gives True:

Define a function:

ValueQ[f[x]] is True:

Scope  (4)

Check immediate and delayed values of symbols:

Check function definitions:

Expressions with head f give True whether or not they actually change:

Use a method that depends on the particular arguments:

ValueQ[LocalSymbol[]] gives True if and only if the local symbol has a value:

Options  (4)

Method  (4)

"SymbolDefinitionsPresent" tests if a symbol has any sort of evaluation definitions associated with it:

"OwnValuesPresent" tests whether any symbol has a direct assignment:

"TrialEvaluation" tests if the input expression will change:

"SymbolDefinitionsPresent" tests whether any code will run, even if it leaves the value unchanged:

The Automatic method gives the same results as "OwnValuesPresent" for symbols:

It agrees with "SymbolDefinitionsPresent" for more general inputs:

The Automatic method checks whether a LocalSymbol has an assigned value:

Properties & Relations  (3)

By default, ValueQ[symbol] only checks symbol for OwnValues, not other kinds of values:

ValueQ[x] is True because a value was assigned directory to x:

ValueQ[f] is False because f itself was not assigned a value:

For more general expressions, ValueQ checks for any kind of symbol definition:

ValueQ is HoldAll:

If x is allowed to evaluate prior to entering ValueQ, the result for y will be given:

Pi evaluates to itself:

Use NumericQ to find out whether there is a numerical value defined:

Possible Issues  (2)

ValueQ checks both user and built-in functions for definitions:

While f has no definitions, Plus does:

ValueQ is HoldAll:

Here x is evaluated before ValueQ sees it:

Use Unevaluated to preserve the HoldAll attribute:

Wolfram Research (1988), ValueQ, Wolfram Language function, https://reference.wolfram.com/language/ref/ValueQ.html (updated 2020).

Text

Wolfram Research (1988), ValueQ, Wolfram Language function, https://reference.wolfram.com/language/ref/ValueQ.html (updated 2020).

CMS

Wolfram Language. 1988. "ValueQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ValueQ.html.

APA

Wolfram Language. (1988). ValueQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ValueQ.html

BibTeX

@misc{reference.wolfram_2024_valueq, author="Wolfram Research", title="{ValueQ}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ValueQ.html}", note=[Accessed: 02-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_valueq, organization={Wolfram Research}, title={ValueQ}, year={2020}, url={https://reference.wolfram.com/language/ref/ValueQ.html}, note=[Accessed: 02-November-2024 ]}