simple javascript code does not work: var count = colors.push(“red”, “green”); -


<html>     <head></head>     <body>         <script>             var colors = new array();             var count = colors.push(“red”, “green”);             alert(count);         </script>     </body> </html> 

i tried on firefox , ie, think version of javascript needs updated?

you need use real quotes, either " or ', example:

var count = colors.push('red', 'green');  

the quote character have used illegal , showing javascript error syntaxerror: unexpected token illegal.

demo:

<!doctype html> <html> <head>   <meta http-equiv="content-type" content="text/html; charset=utf-8">   <title>demo</title>   <script type='text/javascript'>       var colors = new array();       var count = colors.push('red', 'green');       // alert(count);       alert(colors[0]);   </script> </head> <body> </body> </html> 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -