detect logged user wordpress javascript

JavaScript
document.body.classList.contains( 'logged-in' );
Source

Also in JavaScript: