


js sets the default value of function parameters (suitable for cases where no parameters are passed)_javascript skills
May 16, 2016 pm 04:58 PMToday I encountered a problem when writing a div css class library that simulates a js information box. I hope that when I don't pass parameters, "prompt information" will be automatically used as the window title. I tried to write like this
function MessageBox(title="" ){
}
There is no doubt that my operation failed (otherwise I wouldn’t have posted this blog post)
Finally after some Baidu, I found this Good stuff
function test(a){
var b=arguments[0]?arguments[0]:50;
return a ':' b;
}
According to my humble understanding, arguments are probably similar to An array, with subscripts starting from 0, represents the parameters of the function in order
. For example, arguments[0] in the above example represents parameter a
. In fact, arguments[0] ?arguments[0]:50 can also be written as: arguments[0] || 50; The writing method is quite concise. The above is the method to set the default value of function parameter in js.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

New feature in PHP version 5.4: How to use callable type hint parameters to accept callable functions or methods

C++ program to find the value of the inverse hyperbolic sine function taking a given value as argument

PHP Warning: Solution to in_array() expects parameter

C++ function parameter type safety check

Summary of machine learning hyperparameter tuning (PySpark ML)
