_.isFinite() 函數用於檢查傳遞的參數的值是否有限。如果參數具有無限值,則輸出為假,否則為真。我們甚至可以在此函數中執行任何操作,例如加法、減法。
用法:
_.isFinite(object)
參數:
它隻需要一個參數,即需要檢查的參數。
返回值:
如果參數具有有限值,則返回 true,否則返回 false。
Examples:
- 將正數傳遞給 _.isFinite() 函數:
_.isFinite() 函數采用傳遞給它的數字。由於每個數字都有一個有限值,因此當它檢查時,它將聲明它的參數作為有限變量傳遞。因此輸出將是錯誤的。html
<!-- 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() 函數將聲明它的參數作為有限變量傳遞。因此輸出將是錯誤的。html
<!-- 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。它不是有限的。因此,答案是錯誤的。html
<!-- 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’ 具有無限值。因此,答案是正確的。html
<!-- 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 文件中,然後運行它們。
鏈接如下:
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>
相關用法
- Tensorflow.js tf.isFinite()用法及代碼示例
- JavaScript isFinite()用法及代碼示例
- Lodash _.isFinite()用法及代碼示例
- Javascript Number.isFinite()用法及代碼示例
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
注:本文由純淨天空篩選整理自Sakshi98大神的英文原創作品 Underscore.js _.isFinite() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。