₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,345,759 members, 8,519,282 topics. Date: Monday, 16 November 2026 at 02:11 AM

Toggle theme

Can Someone Explain This Line Of Code To Me - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Can Someone Explain This Line Of Code To Me (1921 Views)

1 Reply (Go Down)

Can Someone Explain This Line Of Code To Me by BabyApple(op): 6:08pm On Sep 10, 2018
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array Sort</h2>

<p>The highest number is <span id="demo"></span>.</p>

<script>
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo"wink.innerHTML = myArrayMax(points);

function myArrayMax(arr) {
return Math.max.apply(null, arr);
}
</script>

</body>
</html>


My question is where does (null, arr); comes from
Re: Can Someone Explain This Line Of Code To Me by codemarshal08(m): 7:03pm On Sep 10, 2018
BabyApple:
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array Sort</h2>

<p>The highest number is <span id="demo"></span>.</p>

<script>
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo"wink.innerHTML = myArrayMax(points);

function myArrayMax(arr) {
return Math.max.apply(null, arr);
}
</script>

</body>
</html>


My question is where does (null, arr); comes from
null is built in Javascript . it is used to represent "nothing"
Javascript apply function accepts two (2) parameters. The first parameter is optional . passing null to it means no value.
The arr is used as a parameter in the myArrayMax function definition. parameters are used to pass data to a function.
In your code, the arr is used to pass the values in your point arrays to the myArrayMax function
parameters are defined by programmers.
Re: Can Someone Explain This Line Of Code To Me by fnep2smooth(m): 12:14am On Sep 11, 2018
BabyApple:
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array Sort</h2>

<p>The highest number is <span id="demo"></span>.</p>

<script>
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo"wink.innerHTML = myArrayMax(points);

function myArrayMax(arr) {
return Math.max.apply(null, arr);
}
</script>

</body>
</html>


My question is where does (null, arr); comes from
You are simply telling the program to sort your number you listed in your array by showing the highest number.
Re: Can Someone Explain This Line Of Code To Me by ogunjobiolaide: 3:37am On Sep 11, 2018
fnep2smooth:
You are simply telling the program to sort your number you listed in your array by showing the highest number.
You are on point
Re: Can Someone Explain This Line Of Code To Me by fnep2smooth(m): 6:17am On Sep 11, 2018
ogunjobiolaide:
You are on point
its our work o
Re: Can Someone Explain This Line Of Code To Me by BabyApple(op): 7:11am On Sep 11, 2018
codemarshal08:
null is built in Javascript . it is used to represent "nothing"
Javascript apply function accepts two (2) parameters. The first parameter is optional . passing null to it means no value.
The arr is used as a parameter in the myArrayMax function definition. parameters are used to pass data to a function.
In your code, the arr is used to pass the values in your point arrays to the myArrayMax function
parameters are defined by programmers.
what is the value of arr?
Re: Can Someone Explain This Line Of Code To Me by codemarshal08(m): 8:44am On Sep 11, 2018
BabyApple:
what is the value of arr?
40, 100, 1, 5, 25, 10


View
Math.max.apply(null, arr);
as
Math.max.apply(40, 100, 1, 5, 25, 10)
Re: Can Someone Explain This Line Of Code To Me by kaypompee: 3:21pm On Sep 11, 2018
The JS function returns the largest array value into a html span tag specified by the ID
1 Reply

I Built This Beautiful AI Predictions Webapp With No Single Line Of Code • What Is Wrong With This Line Of Code? • I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) • 2 • 3 • 4

Please I Need Someone Who Can Put Me Through On Php And Mysql. • Can Android Studio Run On 1gb Ram • Sql Error Msg 1801, Level 16 During Execution In Ssms