Getting started with pug

Pug.js tutorial : Pug - variables

Pug tutorial series pugjs tutorial introduction



Overview

In this part of the pugjs tutorial series we will learn about differnt types of variables available in pug.

Variables in pug

There are 4 types of data available in pug which can be stored in pug variables which are explained below :

  1. String Variable : Variable stores String value as shown below :
    													
    //example - 1
    var str = "String";
    //example - 2
    var value = 'This is string type of data' ;
    													
    												

  2. Integer Variable : Variable stores Integer value as shown below :
    													
    //example - 1
    var value = 25
    //example - 2
    var num = 2.57 ;
    													
    												

  3. Array Variable : Variable stores Array values as shown below :
    													
    //example - 1
    var arr = ['A', 'B', 'C']
    													
    												

  4. Object Variable : Variable stores object values as shown below :
    													
    //example - 1
    var obj= = { website: 'nodejsera.com' }
    //example - 2
    var value = { 
    				field: 'web development' ,
    				type : 'education'
    			}
    													
    												


Also we can concatenate these variables as shown below:
  • Concatenating Variables : Variable stores object values as shown below :
    													
    var value = 'World' ;
    var cnct = 'Hello' + value;
    													
    												

What we learned

In this article we learned about the basics of variables in pugjs.

Repository

Get it from :