Both eval and window[] is used to convert string to JavaScript variable or method but little difference is shown below.
window[]
window[]
- This is can access the global variable only
- This is the window object.
- If the variable is undefined, it will return undefined, but not an error.
eval()
- eval() can access the global and local variable value.
- This is interprets arbitrary JavaScript statement.
- If the variable is undefined, you will get and error on executing time.
Example -- Try this jsfiddle , you will enjoy..
No comments:
Post a Comment