CH01-L02 · foundation

Types and variables

Use strings, numbers, and booleans without hidden automatic conversions.

General CELRuns hereDocumented
What will I learn?

You can identify an input value’s type and spot incompatible operands.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

What you will do

You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.

How it works

Every CEL value has a type. Here user.name is a string, user.score is a double in the JSON mode, and the comparison produces a bool. This playground maps JSON numbers to double; therefore the threshold is written as 80.0. CEL does not silently convert the string "86" into a number.

Read the prepared example

The CEL + JSON rule is:

user.name == 'Maya' && user.score >= 80.0

Its input is:

{
  "user": {
    "name": "Maya",
    "score": 86,
    "active": true
  }
}

The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.

Evaluation step by step

  1. user.name == 'Maya' evaluates to true.
  2. user.score >= 80.0 evaluates to true.
  3. true && true returns true.

Your task

  1. Run both modes and inspect the result type.
  2. Change the JSON score to 79 and run again.
  3. Put "86" in quotes, observe the type error, then remove the quotes.

Expected observation: A score of 79 returns false; a quoted score produces an incompatible-type error.

Common mistake

A JSON number and a number inside a self-contained CEL expression can enter the playground with different numeric types. Match the operands or convert explicitly.

Show the explanation

"86" is a string. CEL does not perform an implicit string-to-number conversion.

Knowledge check

Why does "86" >= 80.0 fail instead of returning true?

Key takeaway

Types are part of the rule. Use compatible operands and make conversions visible.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.