Functions declared inside a function body such as the greet() function in your example here:
function sample() {
function greet() {
console.log("hi")
}
}
are private to within the function body and cannot be called from outside of the sample() function scope. You can only call greet() from within the sample() function body unless you somehow assign or return greet after running sample() so you purposely assign greet to some outside variable (which is not present in your example).
Functions are objects so you can create properties on those objects and can then assign a function to a property and can then call it:
function sample() {
console.log("running sample()");
}
sample.greet = function () {
console.log("hi")
}
sample.greet();