javascript function error while adding blank functions

I am relatively new to javascript. following is my .js -file which I am importing in my html file-

function primaerror(strmessage) 
{
alert(strmessage);
return null;
}
function showdiagnosis(string pid){}
function showimages(){}
function showimage(){}

I get :

 Error  = "Expected ')'. Line:5 Char:31"

Please help me where the error could be?

Thanks


Javascript doesn't have the keyword string in first place.

You are not supposed to give datatypes for variables, you may not even use var keyword before formal parameters.

Javascript interpreter can understand the type of the value a variable pointing. Since, variables doesn't have any types in particular and can be messed up any way, hence it is called weakly typed language .

Changing function showdiagnosis(string pid){} to

         `function showdiagnosis(pid){}`

If you need you can use typeof keyword to know the type value passed through pid.

For example:

          function showDiagnosis(pid){

              if(typeof pid=='string')
              //................

          }

This link is valuable and you may want to check it:

Finding variable type in javascript

Check if a variable is a string

Check whether variable is number or string in javascript

And use proper naming conventions for function names, variables. In general, Javascript community follows showDiagnosis(pid) for your case. Start with small letter and capitalize every first letter of distinct words in the name so that it makes some sense for readers and increases readability.


Since JavaScript is a dynamically-typed language, it doesn't need (and don't allow) type declaration for function parameters, so you should remove string from function showdiagnosis(string pid){} .

function primaerror(strmessage) 
{
alert(strmessage);
return null;
}
function showdiagnosis(pid){}
function showimages(){}
function showimage(){}

You may want to check the type of the parameter manually if you need to.

See also: Set type for function parameters?

链接地址: http://www.djcxy.com/p/94988.html

上一篇: 如果包含字符串,则重定向knockout js可观察

下一篇: 在添加空白函数时出现javascript函数错误