Use Math.sqrt() to calculate square roots in JavaScript and handle negative inputs by returning NaN or validating data types.