You should know that if the target table already has a <caption> element, then using this method won’t add a new one, but instead returns a reference to the one that is already created.
Note: you can use the deleteCaption() method to remove a <caption> element from a table.
createCaption() Method Syntax:
createCaption() Method Parameter
The method does not take an argument.
createCaption() Method Return Value
If the target <table> did not have a <caption> then calling this method will create a new one and return a reference to that element.
But if the target table has a <caption> already, then the return value of this method will be a reference to that caption instead. This means in such case, the method won’t create a new one.