The major difference is that Mermaid.JS has a longer history than D2 lang. Mermaid JS was first released 2014 while D2 lang was introduced in 2022. Another difference is that more people have written about using Mermaid and that is has been used in more projects. However, where D2 lang wins is on the ability to customise the look over the diagrams and the different choices for export without having to use a headless browser.