function to create an element javascript

JavaScript
// A function to create elements in JS
function elementFactory(tag, text) {
    const el = document.createElement(tag);
    el.textContent = text;
    return el;
}

const someListItem = elementFactory("li", "some text"); 
let p = document.createElement('p');
Source

Also in JavaScript: