/    Sign up×
Community /Pin to ProfileBookmark

Breaking a Function

Is there a way to prematurely end a function using some command inside a function?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Jul 20.2008 — I don't believe there is because the break statement is used to break out of loops. The only way is with a return statement to my knowledge. If a certain condition is met you could use the return statement. What exactly are you trying to do? Do you have some code that we could help you with?
Copy linkTweet thisAlerts:
@HoboScriptJul 20.2008 — I don't believe there is because the break statement is used to break out of loops. The only way is with a return statement to my knowledge. If a certain condition is met you could use the return statement. What exactly are you trying to do? Do you have some code that we could help you with?[/QUOTE]

That's exactly what a return statement can be used for. Prematurely ending a function.
Copy linkTweet thisAlerts:
@KorJul 21.2008 — [B]return[/B] not only ends the run of a function but also, as its name says, may return a variable. If nothing specified is return, the return value is [I]undefined[/I]
×

Success!

Help @someone3426 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...