Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
理解此javascript函数代码 函数为空{ var len=s.长度 变量i 对于(i=0;i_Javascript_Html - Fatal编程技术网

理解此javascript函数代码 函数为空{ var len=s.长度 变量i 对于(i=0;i

理解此javascript函数代码 函数为空{ var len=s.长度 变量i 对于(i=0;i,javascript,html,Javascript,Html,它在字符串s中循环并检查每个字符是否为空格。如果存在空格以外的字符,则函数返回false,因为字符串不是空的。如果字符串为空或仅包含空格,则函数返回true,因为字符串为空。函数为空{//名为“isBlank”的函数接受一个参数,该参数是从外部传递的 function isBlank(s){ var len = s.length var i for(i=0; i<len; ++i) { if(s.charAt(i)!= " ") return fal

它在字符串s中循环并检查每个字符是否为空格。如果存在空格以外的字符,则函数返回false,因为字符串不是空的。如果字符串为空或仅包含空格,则函数返回true,因为字符串为空。

函数为空{//名为“isBlank”的函数接受一个参数,该参数是从外部传递的
function isBlank(s){
    var len = s.length
    var i
    for(i=0; i<len; ++i) {
        if(s.charAt(i)!= " ") return false
    }
    return true
}
var len=s.length//将参数“s”的长度赋给局部变量“len” var i//声明一个新的局部变量“i”
对于(i=0;i,函数检查字符串是否为空

function isBlank(s){ // it is a function named 'isBlank' that accept one parameter, that the parameter is something passed from the outside
    var len = s.length // Assign the length of parameter 's' into a local variable 'len'
    var i // Declare a new local variable 'i'
    for(i=0;i<len;++i) { // This is a 'loop', you can google it
        if(s.charAt(i)!= " ") return false // if any character inside the parameter 's' is not an empty space, that means it isn't blank, so return false
    }
    return true; // If code reach this line that means 's' is either with 0 length or all characters of it are an empty space
}

用于(i=0;i@OrangeFlash81为什么你拒绝了我的编辑?!@MehdiDehghani在我意识到你有一个挂起的编辑之前做了一个几乎相同的更改。对不起。为什么你不能阅读这些方法、属性等的文档?这是非常基本的javascript,你可以在5分钟内学会这是一种检查字符串是否充满空格的糟糕方法…@MehdiDehghani这种方法对于
“hello”
来说是失败的。另一方面,循环确实有点过分,你是对的。
for(i=0;i<len;++i) { // iterates through the string
    if(s.charAt(i)!= " ") // checks whether character at index i of string s is not equal to " ".
        return false 
}