Google News
logo
Scala - Interview Questions
Why do we use =(equal) operator in Scala function?
You can create a function with or without = (equal) operator. If you use it, the function will return value. If you don't use it, your function will not return anything and will work like the subroutine.

Example :
object MainObject {  
   def main(args: Array[String]) {  
        var result = functionExample()      // Calling function  
        println(result)  
    }  
    def functionExample() = {           // Defining a function  
          var a = 10  
          a  
    }  
}  ​
Advertisement