6. Modern JavaScript Syntax

Use Modern JavaScript in UI5 Projects

Why it matters

With the end of official Internet Explorer support, there is no need to limit yourself to outdated syntax. Modern JavaScript makes code cleaner, shorter, and easier to maintain.

Key recommendations

  1. Don’t copy outdated examples from the documentation

    Old UI5 examples often use legacy syntax. Always refactor the code you write or edit to modern standards.

  2. Asynchronous functions — only Promise or async/await

    Don’t use callback style for async work. Always return a Promise or use async/await.

  3. Use let and const instead of var

    This prevents errors related to variable scope.

  4. Use modern array methods and standard functions

    Methods like map, filter, find, reduce make code shorter and clearer.

    Before:

    for (var i = 0; i < arr.length; i++) {
      if (arr[i].active) {
        ...
      }
    }
    

    After:

    arr.filter(item => item.active).forEach(item => { ... });
    
  5. For oData, use Promise wrappers

    This allows you to use async/await and avoid nested callbacks.


What to do with old projects

If you work with legacy code, you don’t need to rewrite everything at once. Just gradually improve individual functions or modules as you make changes. This will improve project quality without extra time costs.