Const question about scope

const action = {
  type: 'LOGIN'
}
// Define an action creator here:
function actionCreator() {
  return action
}

I thought constant can only be used locally, so howcome function actionCreator() can access const action?

const scrope is blocked, so when you define action const in your code it can not access via its outer blocked but can access via inner block.

So in short, YES you can use const action in actionCreator().

2 Likes