Solution:
As @FluffyKitten explained, Post IDs are numbers, not strings. The issue arises because wp_localize_script expects an array as the third parameter, but a non-array value was being passed.
To fix the problem, make sure you pass an array. For example:
wp_localize_script('extra-script', 'my_postid', array( get_the_ID() ) );