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.
- Check if
valis strictly astring. - check if the string has at least one character (length > 0).
- Return
trueonly if both are true. Returnfalsefor empty strings, numbers, or null/undefined.
01EXAMPLE 1
Input
val = "N"Output
trueExplanation: It is a string and not empty.
Constraints
- Must handle non-string types safely without crashing.
- One character minimum.
TypesLogicProfessional
JavaScriptSystem handles I/O — write your function only
Loading...
4 Hidden
Input Arguments
val"Pro"
Expected Output
true
Click RUN to test your solution