【问题标题】:How to use typeof operator to check if function is a string如何使用 typeof 运算符检查函数是否为字符串
【发布时间】:2021-09-27 10:01:11
【问题描述】:

任务说明 您在本活动中的任务是创建一个名为 isString 的函数,该函数接受三个参数(a、b、c)。此函数执行以下操作: 它使用 typeof 运算符和严格相等比较来检查所有三个参数 a、b 和 c 的类型是否为字符串。 如果每个参数都是字符串,则返回消息字符串。 如果三个参数中的任何一个不是字符串,则返回消息不是字符串

我不确定如何创建名为 isString 的函数,然后在其下放置三个参数。 我也不确定如何使用 typeof 运算符来完成比较。需要更多详细信息。

/*
Follow the instructions - Create a function called "isString" that takes 3 arguments (x1, x2, x3)
- check if each argument is a string using typeof.
- If each argument is a string, return "strings"
- If each argument is NOT a string, return "not strings"

*/


//Write your code here
////////////////////////////////////////

////////////////////////////////////////

//open the browser console to check results
console.log('results: ', isString('a', 'b', 'c'));

//don't change this line
if (typeof module !== 'undefined') {
  module.exports = isString;
}

【问题讨论】:

标签: javascript string function typeof strict


【解决方案1】:
const isString=(a,b,c)=>{
if( ((typeof a)=="string") && ((typeof b)=="string") && ((typeof c)=="string")){
return "strings";
}
return "not strings";
}

【讨论】:

    猜你喜欢
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    相关资源
    最近更新 更多