Type Integrity Guard

MediumAcc. 71.2%
+45 XP 18

Professional Type Guards

A common error in logic is checking for a string's length without verifying if it is actually a string. If the value is null, checking .length will crash your script.

A "Strong Type Guard" checks both the type and the value property in a single safe expression.

The Assignment

Your function receives a parameter val.

  1. Check if val is strictly a string.
  2. check if the string has at least one character (length > 0).
  3. Return true only if both are true. Return false for empty strings, numbers, or null/undefined.

01EXAMPLE 1

Inputval = "N"
Outputtrue

Explanation: It is a string and not empty.

Constraints

  • Must handle non-string types safely without crashing.
  • One character minimum.
TypesLogicProfessional
JavaScript
Loading...
4 Hidden

Input Arguments

val"Pro"

Expected Output

true

Click RUN to test your solution