Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: engine compatibility note

Several operators can be applied to objects of any type.

Table of Contents

Info
titleEngine Compatibility

In the node pico engine, the target types for the as() function and the results returned from the typeof() function are these values:

  • "Array"

  • "Boolean"

  • "Map"

  • "Null"

  • "Number"

  • "RegExp"

  • "String"


The following coercions are valid:

  • Strings can be coerced to numbers and regular expressions.
  • Numbers can be coerced to strings.
  • Regular expressions can be coerced to strings.
  • Any expression can be coerced to Boolean.

An error is thrown for other attempted coercions, unless the value being coerced by as() is already of the target type.


as()

The as() operators coerces objects of one type to be an object of another. The target type is given as a string argument to the operator. The following types are available in KRL:

...

For example, the following constructs a string and then turns it into a regular expression that can be used by the replace() operator:

Code Block
languagejavascript
themeConfluencelanguagejavascript
("re/q=" + q + "/i").as("regexp")

...

The isnull() operator returns true of the object is null (undefined) and false otherwise. 


Code Block
languagejavascript
doesnotexist.isnull(); // returns true

 


klog()

The klog() operator writes an optional message, given as a string argument, and the value of the object to the debug log. 

Code Block
languagejavascript
themeConfluencelanguagejavascript
x = some_arr.filter(function(x){x == 5}).klog("Value after filter: ").head();

...

The typeof()operator returns the type of the object to which it is applied. For example:

Code Block
languagejavascript
themeConfluencelanguagejavascript
nums = [1, 2, 3]
nums_type = nums.typeof() // nums_type = "array"

...