alert (alert (1)) - displays undefined alert (alert (1) && alert (2));
- You should not ask a new question by changing the text of the question fifteen hours after its publication. - Igor
- learn.javascript.ru/logical-ops - Duck Learns to Hide
- The modified version was not preserved right away - Elvis
|
3 answers
Thinking is great, but sometimes easier to read:
https://www.w3schools.com/jsref/met_win_alert.asp
Window alert () Method
Return Value: No return value
(Returns: Returns nothing)
Does not return:
var test = alert(1); console.log(test); Returns:
var test = confirm("Are you sure?"); console.log(test); Returns:
function multiply(a, b) { return a * b; } console.log(multiply(2, 3)); Does not return:
function multiplyAndShow(a, b) { var c = a * b; document.getElementById("result").innerText = c; } console.log(multiplyAndShow(2, 3)); <span id="result">empty</span> - when alert (1) is displayed 1 - is this a return? I think because of this I get confused - Elvis
- @Elvis
alertdisplays1, because this is whatalertdoes — it shows a window with a string representation of what is passed to it as a parameter. It has nothing to do with the value returned by thealertfunction. - Igor - Can you please provide an example of a function that returns a value? - Elvis
- @Elvis added an example in response - Igor
- Thank you very much! Did I understand correctly that something is returning - these are functions, where I have to answer or enter something? That is, there is usually not a single action - Elvis
|
will print first 1 (internal alert), and then undefined (what the internal alert returned), and at the end will remain undefined (what the external alert returns)
- I do not fully understand. Above wrote that returns nothing, but you write in 2 brackets that he returned an internal alert: ( - Elvis
- @Elvis in terms of javascript-a - “returns nothing” is the same as “returns
undefined” - Igor
|
The alert() function returns no value . It means that
alert(1) It is not a convenient parameter for any function, including the alert() :
alert(alert(1)) // alert(1) ошибочный параметр для alert() - What does an error parameter mean? - Grundy
|