Edit in JSFiddle

if (!document.body.hasAttribute('id')){
    
    // 속성 추가
    var elem = document.body.setAttribute('id', 'setAttribute');
    console.log('append: ' + document.body.id); 
    
    // 속성 삭제
    document.body.removeAttribute('id');
    
    console.log('remove: ' + document.body.id);
     
}