Q:

The function doesn't validate a phone number

I want to check a number (var phone). It should be valid, if it has from 7 to 8 characters, one of which CAN be a dash (-).
If the number is greater than 8 or less than 7 characters, the function should return false (obviously it doesn't). Where's the problem?
No matter what I assign to var phone, console.log shows that everything is valid. By the way, I'm a beginner to JavaScript.
var phone = "123-56";

function validate(phoneNumber) {
    if (phoneNumber.length > 8 ||
        phoneNumber.length < 7) {
        return false;
    }
var vals = phoneNumber.split("-");

if (isNaN(vals[0]) || isNaN(vals[1])) {
    return false;
}
return true;
}

if (validate) {
console.log("The number " + phone + " is valid.");
} else {
console.log("The number " + phone + " is NOT valid.");
}

A:

the following
if(validate)

Means "Does the object validate exist?"
What you have to do is to use the result of the execution of your validation function :
if (validate(phone)) {
    console.log("The number " + phone + " is valid.");
} else {
    console.log("The number " + phone + " is NOT valid.");
}

where if (validate(phone)) is some kind of short hand for 
let validated = validate(phone);    // you store the result of the validate function into a new variable
if (validated) {}

