• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • CSPro Program Structure
      • Programming Standards
      • Change Code Properties
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
      • Procedural Sections
      • Logic
      • Language Elements
      • JavaScript Use in CSPro
        • Overview
        • JS Namespace
        • JS.eval Function
        • JS.invoke Function
        • JS.getValue Function
        • JS.getValueJson Function
        • JS.hasValue Function
        • JS.setValue Function
        • JS.setValueFromJson Function
        • JavaScript User-Defined Functions
        • CSPro ⇄ JavaScript Value Conversions
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

JS.hasValue Function

Format
b = JS.hasValue(name);
Description
The JS.hasValue function returns whether a JavaScript variable or property is defined (not undefined).
The string expression name is evaluated and can refer to a variable in CSPro's JavaScript global execution context or an object's property if the object exists globally. For example, the following values can be specified as a name:
  • myFunction
  • globalThis.myFunction
  • myObject.myProperty
  • myObject['my' + 'Property']
Return Value
The function returns a logical value of 1 (true) if the variable or property is defined, and 0 (false) if undefined. If the JavaScript evaluation ends in an uncaught exception, the exception's message is suppressed (unlike other functions in the JS namespace) and the function returns false.
Example (Variables)
JS.hasValue("csproVersion");          // 0
JS.setValue("csproVersion", 8.1);
JS.hasValue("csproVersion");          // 1
JS.eval("csproVersion = undefined;");
JS.hasValue("csproVersion");          // 0
Example (Object Properties)
JS.setValueFromJson("france", ' { "name": "France",        '
                             
'   "capital": "Paris",      '
                             
'   "currency": "Euro",      '
                             
'   "republicNumber": 5,     '
                             
'   "languages": ["French"] }');

JS.hasValue("france");                          // 1
JS.hasValue("globalThis.france");               // 1
JS.hasValue("france.capital");                  // 1
JS.hasValue("france['CAPITAL']");               // 0
JS.hasValue("france['CAPITAL'.toLowerCase()]"); // 1
JS.hasValue("france.languages[0]");             // 1
JS.hasValue("france.languages[1]");             // 0
JS.hasValue("france[throw new Error()]")        // 0
See also: JavaScript Use in CSPro, JS Namespace, JS.getValue Function, JS.getValueJson Function, JS.setValue Function, JS.setValueFromJson Function