Home > Software engineering >  When to use double quotes/single quotes in parentheses?
When to use double quotes/single quotes in parentheses?

Time:03-23

When to use and not use single or double quotes within functions?

for example:

function convertToInteger(str) {
  return parseInt(str); // why do we not use double-quotes here? is this as simple as we never use quotes around arguments when calling a function?
}

convertToInteger("56");

CodePudding user response:

the variables inside the function are called arguments. They serve to store the item you passed. As you passed it, it will use whatever value you enter, but if you put a value in quotes, you would be setting a fixed value.

CodePudding user response:

Variable value should be in quotes , variable name should not be in quotes .

convertToInteger("56");

or

var datavalue="56";

convertToInteger(datavalue);

CodePudding user response:

function log(x) { // we create a function that accepts one parameter called x 
  console.log(x) // then we do something with the parameter we pass
}

// here we're calling the log() function 
// and passing the string 'Hello, World!' to the function 
// which accepts one parameter
log('Hello, World!')  

Reference ( Functions - Javascript )

  • Related