Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Define a Function to Check If a Variable is a String</title> </head> <body> <script> // Defining a function function isString(myVar) { return (typeof myVar === 'string'); } // Sample variables var x = 10; var y = true; var z = "Hello"; // Testing the variables document.write(isString(x)); // Prints: false document.write("<br>"); document.write(isString(y)); // Prints: false document.write("<br>"); document.write(isString(z)); // Prints: true </script> </body> </html>