1

I created a function in Javascript

function addName(okDelete = true){

	amountExtraStudents++;
	if(amountExtraStudents > 2){
	
		preisAktuell = 60;
	
	}
	if(!okDelete){
		jQuery('#teilnehmerExtra').append('<div class="teilnehmer-1"></div>');
	}else{
		jQuery('#teilnehmerExtra').append('<div class="teilnehmer-2"></div>');
	}
	eintragNummer++; 
	updateButtons();
	
}

But in Edge I get this error:

enter image description here

In Safari I dont get any Error - but the Function - and all the other functions in the rest of the Script Block are not working.

It works out fine in Chrome, Firefox and Opera, but not in Safari, IE and Edge...

Is there something incompatible with the Browser?

6
  • Why you have an expression as parameter? Commented May 24, 2016 at 15:17
  • In ES6 it's good stuff, but anything before that it's no good. @SimonSchüpbach Commented May 24, 2016 at 15:18
  • Isnt that giving the possibility to set a "standard" value, if no parameter is given? Commented May 24, 2016 at 15:18
  • Should only work in Chrome or FF, surprised it works in Safari? developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented May 24, 2016 at 15:18
  • @chillNUT - it doesnt work in Safari! Any work Around? Commented May 24, 2016 at 15:19

1 Answer 1

10

The error is occuring when you use the 'default parameters' feature introduced in ES6. Edge does not support it.

An ES5 version would be:

function addName(okDelete){
    if (typeof okDelete === "undefined") {
        okDelete = true;
    }

You might also consider using a tool such as Babel to transpile your ES6 into ES5.

Sign up to request clarification or add additional context in comments.

2 Comments

Was editing my answer without realizing you beat me, oops! +1, this is the answer OP wants.
Thank you very much! This is working out fine - I didnt know, that this is not possible in ES5... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.