When I am putting a WordPress value inside the attribute tag, for example, the following method does not need esc_attr
e.g.
// JS code
alert('<?php echo get_bloginfo('name');?>');
the following method does need esc_attr
// JS code
alert('<?php echo esc_attr($post->post_title);?>');
What is the convention used?