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
-
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.
-
Asynchronous functions — only Promise or async/await
Don’t use callback style for async work. Always return a Promise or use async/await.
-
Use let and const instead of var
This prevents errors related to variable scope.
-
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 => { ... }); -
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.