Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Function with parameters that span multiple lines

I want to use a function in javascript that has many parameters that likely have long names. I want it to look something like this:

functionName( parameter1,
              parameter2,
              parameter3 );

so far I've tried doing the following to no avail:

functionName( parameter1, \
              parameter2, \
              parameter3 );

I understand that "\" is supposed to have things continue on to the next line. Am I missing something?

like image 255
user3199313 Avatar asked Jan 15 '14 17:01

user3199313


People also ask

Can a function have multiple parameters JavaScript?

When you call a function in JavaScript, you can pass in any number of arguments, regardless of what the function declaration specifies. There is no function parameter limit. In the above function, if we pass any number of arguments, the result is always the same because it will take the first two parameters only.

How break JavaScript code into multiple lines?

There are two ways to break JavaScript code into several lines: We can use the newline escape character i.e “\n”. if we are working on the js file or not rendering the code to the html page. We can use the <br> tag.

How do you write a multi line string in JavaScript?

There are three ways to create strings that span multiple lines: By using template literals. By using the + operator – the JavaScript concatenation operator. By using the \ operator – the JavaScript backslash operator and escape character.

What is a multiline function?

using a multiline function: a function whose defining rule consists of. several pieces.


1 Answers

You do not need any special character to span lines. Your original is fine:

functionName(parameter1,
             parameter2,
             parameter3) {}
like image 140
Wayne Avatar answered Nov 09 '22 23:11

Wayne