Your function a() is set in global context. Here global context is window object.
console.log(kk) it will look for window.kk, no variable has been set in window. So it gives you undefined.
So try to invoke the function a() first and then do your print.