Why isn’t my button working?

Asked

Viewed 37 times

-2

function click(){
  console.log('clicou')    
}

   
   <div id="primeira">
        Números (entre 1 e 100): <input type="number" name="" id="tab"> 
        <input type="button" id="but" value="Adicionar" onclick="click()">
    </div>
    

I wanted to know why click() does not work

  • changes the name of the function, instead of clicking it can be clicks or qq another name that is not reserved

1 answer

1

You may not use any reserved keyword as a variable name or function. This includes all keywords currently used by the language and all others kept in reserve for future versions of Javascript. Javascript designers, however, cannot predict each keyword that the language may use in the future. Using the isolated word type that currently appears in the reserved keywords list, you run the risk of a conflict in the future.

Due to the potential conflict with future keywords, the use of word combinations for variable names is always a good idea. Word matching probably does not appear in the reserved word list.

You can use one of the conventions to associate multiple words as one. One convention is to put an underscore character between words; another is to start the word combined with a capital letter within the compound name. These two examples are valid variable names:

    minhaVar   minha_var

Variable names have some other important restrictions. Avoid all symbols except for the underscore character. Also, the first variable name character cannot be a number.

function minhaFunction(){
   console.log('clicou')    
}
<div id="primeira">
    Números (entre 1 e 100): <input type="number" name="" id="tab"> 
    <input type="button" id="but" value="Adicionar" onclick="minhaFunction()">
</div>

Reserved word case note that will give a mistake

function case(){
   console.log('clicou')    
}
    <div id="primeira">
    Números (entre 1 e 100): <input type="number" name="" id="tab"> 
    <input type="button" id="but" value="Adicionar" onclick="case()">

I used the word variable a lot but everything that was said is for function.

Source Javascript to the Bible

List of reserved words

Browser other questions tagged

You are not signed in. Login or sign up in order to post.