Book Image

Web Development with Jade

By : Sean Lang
Book Image

Web Development with Jade

By: Sean Lang

Overview of this book

Table of Contents (16 chapters)

Built-in logical operators


Writing JS can start to look ugly and doesn't really match with the indentation-based syntax that Jade uses, so we have several built-in logical operators that do the same thing, but are easier to write.

Here are a few examples:

If / else / else if

Jade

HTML

- name = "Bob"
if name == "Bob"
  h1 Hello Bob
else if name == "Joe"
  h1 Hello Joe
else
  h1 My name is #{name}
<h1>Hello Bob</h1>

Unless

Jade also provides unless which is equivalent to if (!(expr)), as illustrated in the following code snippet:

Jade

HTML

- name = "Bob"
unless name == "Bob"
  h1 My name is #{name}
else
  h1 Hello Bob
<h1>Hello Bob</h1>

Cases

Jade

HTML

- name = "Bob"
case name
  when "Bob"
    p Hi Bob!
  when "Alice"
    p Howdy Alice!
  default
    p Hello #{name}!
<p>Hi Bob!</p>

Each loops

Each is used for iterating over arrays and objects and is written in the following syntax:

each VAL[, KEY] in OBJ

An example is given in the following code snippet:

Jade

HTML...