azgooon
azgooon

Reputation: 302

SCRIPT1006: Expected ')'

In the function below, IE says that ')' is missing:

function padZeros(num, size = 4) {
    var s = num+"";
    while (s.length < size) {
        s = "0" + s;
    }
    return s;
}

What am I missing?

Upvotes: 14

Views: 12760

Answers (4)

Balamurugan
Balamurugan

Reputation: 159

In Microsoft Edge an d IE is not supported direct pass the value in function. It is consider as Error file, So that we are getting error

Try below code

function padZeros(num) {
    var size = 4;
    var s = num+"";
    while (s.length < size) {
        s = "0" + s;
    }
    return s;
}

Upvotes: 0

gfh
gfh

Reputation: 9

This is happening because you are trying to run the Javascript ES6 code on non supported IE browser.

ECMAScript 6, also known as ECMAScript 2015, is the latest version of the ECMAScript standard. ES6 is a significant update to the language, and the first update to the language since ES5 was standardized in 2009.

Please go through the below docs for more details

Funtion with default value : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters#Syntax

Supported Browser Lists : https://kangax.github.io/compat-table/es6/

Here is the update code for all browsers

Upvotes: 0

Umashankar
Umashankar

Reputation: 709

This is happening because you are trying to run the Javascript ES6 code on non supported IE browser.

ECMAScript 6, also known as ECMAScript 2015, is the latest version of the ECMAScript standard. ES6 is a significant update to the language, and the first update to the language since ES5 was standardized in 2009.

Please go through the below docs for more details

Funtion with default value : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters#Syntax

Supported Browser Lists : https://kangax.github.io/compat-table/es6/

Here is the update code for all browsers

function padZeros(num, size) {
 var s = num+"";
 while (s.length < size) {
  s = "0" + s;
 }
 return s;
}
padZeros(10,4)/*10 is your num and 4 is your pad size*/

Upvotes: 2

Jaromanda X
Jaromanda X

Reputation: 1

The issue is that Internet Explorer does not understand "default values for arguments" - this is ES2015+ and since development for IE stopped a long time ago, there's no way the new fangled ES2015+ syntax will ever work for IE

Try using a transpiler like babel for example until IE officially dies!

function padZeros(num) {
    var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;

    var s = num + "";
    while (s.length < size) {
        s = "0" + s;
    }
    return s;
}

Upvotes: 20

Related Questions