Question:
Which value does x have after execution of the following code?
function hi(name) {
return 'Hi ' + name + '!';
}
let h1 = hi('Selva');
let h2 = hi('Pola');
let x = h1 + ' ' + h2;
Answer:
'Hi Selva! Hi Pola!'
> This is a function declaration & not a function expression
> name of the function: hi
> parameter: () parameter is name
> statement: return 'Hi ' + name + '!'; enclosed in curly brackets
> the function must have a return statement that specifies the value to return
> the value type in this case is a string
> strings can be used with single or double quotes
> we can concatenate the string with a '+' sign
> declared a variable h1 and initialized it with a value
> the value will be, the output we get when we 'call' the function hi with the argument
> in this case the argument 'hi (name)' is 'hi ('Selva!')'
> the value will be 'Hi Selva!'
> declared another variable h2 and initialized it with a value
> the value will be, the output we get when we 'call' the function hi with the argument
> in this case the argument 'hi (name)' is 'hi ('Pola!')'
> the value will be 'Hi Pola!'
> declared another variable x and initialized it with a value
> this variable x concatenates the variables h1 & h2 with a space
> space is denoted by placing empty quotes between the '+' signs
No comments:
Post a Comment