Lazy and right-to-left evaluation in the node tree
When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.

Taken from this page:

https://docs.blender.org/manual/en/dev/render/cycles/optimizations/nodes.html

This page also describes how the node tree is evaluated.