_.isFinite()函數:
- 用於檢查傳遞的參數的值是否為有限值。
- 如果參數具有無限值,則輸出為false,否則為true。
- 我們甚至可以在此函數中執行任何操作,如加,減。
用法:
_.isFinite(object)
參數:
它僅接受一個參數,這是需要檢查的參數。
返回值:
如果參數具有有限值,則返回true,否則返回false。
例子:
- 將正數傳遞給_.isFinite()函數:
_.isFinite()函數采用傳遞給它的數字。由於每個數字都有一個有限值,因此在檢查時會聲明將其參數作為有限變量傳遞。因此輸出將為假。<!-- Write HTML code here --> <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log(_.isFinite(10)); </script> </body> </html>
輸出:
- 將負數傳遞給_.isFinite()函數:
_.isFinite()函數采用傳遞給它的數字。由於它是一個負數,但仍然有一個值,因此,出於與上述_.isFinite()函數相同的原因,它會將其參數聲明為有限變量。因此輸出將為假。<!-- Write HTML code here --> <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log(_.isFinite(-10)); </script> </body> </html>
輸出:
- 將定義的變量傳遞給_.isFinite()函數:
_.isFinite()函數采用傳遞給它的參數,該參數此處為變量“ a”。然後,它檢查“ a”的值為10。它不是有限的。因此,答案是錯誤的。<!-- Write HTML code here --> <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> var a=1000; console.log(_.isFinite(a)); </script> </body> </html>
輸出:
- 傳遞變量而不初始化_.isFinite()函數:
_.isFinite()函數采用傳遞給它的參數,該參數此處為變量“ a”。然後,它會檢查“ a”的值,該值未定義,因此也不固定。這意味著“ a”具有無限值。因此,答案是正確的。<!-- Write HTML code here --> <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> var a; console.log(_.isFinite(a)); </script> </body> </html>
輸出:
注意:這些命令在Google控製台或firefox中將無法使用,因為需要添加這些尚未添加的其他文件。
因此,將給定的鏈接添加到您的HTML文件,然後運行它們。
鏈接如下:
<!-- Write HTML code here -->
<script type="text/javascript" src =
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
相關用法
- Javascript Number.isFinite()用法及代碼示例
- JQuery after()用法及代碼示例
- underscore.js max()用法及代碼示例
- JQuery on()用法及代碼示例
- JQuery one()用法及代碼示例
- JQuery first()用法及代碼示例
- underscore.js map()用法及代碼示例
- JQuery last()用法及代碼示例
- underscore.js min()用法及代碼示例
- JQuery eq()用法及代碼示例
- JQuery val()用法及代碼示例
- underscore.js where()用法及代碼示例
- underscore.js some()用法及代碼示例
- underscore.js contains()用法及代碼示例
- underscore.js first()用法及代碼示例
注:本文由純淨天空篩選整理自Sakshi98大神的英文原創作品 Underscore.js | _.isFinite() with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。