No, that's misleading. The result is not typecast to string, it's not combined into a single string, many outputs become an array. And it's not whatever is printed to the console, it's whatever was sent to the pipeline output. Printing to the console is separate in PowerShell. Unlike in Linux world where the main way appears to be abuse of stderr for things which are informational and not errors, PowerShell has many output streams, and only one of them is the output of a function. e.g.
function test {
"hello"
5
write-host "world"
}
$result = test
$result contains "hello",5 the output of the function and 5 is still typed as an integer - not string and not a single string - and the console prints "world".
And it does this to make it work like a Unix shell, because if you write a command and get some output, then want to batch some commands together in a function and get no output except what you explicitly "return", that would be annoying.
> "functions don't actually have return statements"
They do actually have return statements (for control flow).
(And if you make classes with methods, they have traditional programming language features - called with parens, lexical scope, return statement controls the return value).
And it does this to make it work like a Unix shell, because if you write a command and get some output, then want to batch some commands together in a function and get no output except what you explicitly "return", that would be annoying.
> "functions don't actually have return statements"
They do actually have return statements (for control flow).
(And if you make classes with methods, they have traditional programming language features - called with parens, lexical scope, return statement controls the return value).