DEV Community

Discussion on: Instructions vs Expressions

Collapse
 
stereobooster profile image
stereobooster • Edited

Unit is a subtype of scala.AnyVal. There is only one value of type Unit, (), and it is not represented by any object in the underlying runtime system. A method with return type Unit is analogous to a Java method which is declared void.


void is a Java keyword.

Used at method declaration and definition to specify that the method does not return any type, the method returns void. It is not a type and there is no void references/pointers as in C/C++.


A variable that has not been assigned a value is of type undefined. A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned.

undefined (in JS) ~ void (in Java) ~ Unit (Scala)

Maybe you meant expressions vs statements

Statement:

if (a > b) { return 1 } else { return 2 }
Enter fullscreen mode Exit fullscreen mode

Expression:

a > b ? 1 : 2
Enter fullscreen mode Exit fullscreen mode