SweetAlert2 syntax error on Internet Explorer 11

Tags: , , ,



I’m using the exactly code of SweetAlert2 examples page:

swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.value) {
    swal(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
})

Works fine on Firefox and Chrome, but Internet Explorer shows SCRIPT1002: Syntax Error and not run the script…IE flag this portion as syntax error:

}).then((result) => {

Thanks for any help

Answer

(result) => {} is an arrow function which is completely unsupported in IE. To fix this you’ll have to use a traditional anonymous function:

swal({
  // options...
}).then(function(result) {
  if (result.value) {
    swal('Deleted!', 'Your file has been deleted.', 'success');
  }
});


Source: stackoverflow