What is the `name` keyword in JavaScript?

前端 未结 4 673
温柔的废话
温柔的废话 2020-12-03 17:23

When I typed this apparently innocent snippet of code:

values.name

gedit highlighted name as a keyword. However,

4条回答
  •  旧巷少年郎
    2020-12-03 17:45

    (I know this was asked 2 years ago but, ...) This happened to me also, for example this below would not work.

    name = document.getElementById('nombre');
    //something else
    name.className = 'thinking';
    

    Instead I changed it to

    username = document.getElementById('nombre');
    //something else
    username.className = 'thinking';
    

    and it did work! Yeah, alright that's all, but it's something I find maybe quite interesting, also because of the 'name' attribute of the 'a' tag. Something to watch out for.

提交回复
热议问题