Jump to content

Js Tutorial


webmaster@indigotide.com
 Share

Recommended Posts

Hi, I am a newbie to JS and I was looking at the Tutorials for bitwise comparisons for a practice script. I noticed that JS Operators does not mention bitwise operators, and likewise neither does JS Comparisons. Something like if( x & 8 ). Other than that, I have already learned a lot just by reading the Tutorials and posts. Thanks for the great site. PS, I found what I needed on Google...just FYI. Thanks again.

Link to comment
Share on other sites

Bitwise operators (in any language - JS, PHP, etc.) are very difficult to explain. Tell me, how long was the article that actually made you understand them?I mean, anyone can say "bitwise operators work on their operands in their bit representation, whereas other operators work on the full representation", but to really see where and how this makes a difference, a whole (and I bet a long...) article is needed. W3Schools is for beginners, and bitwise operators are difficult to explain even to not-so-much-newbies, so imagine how much harder would be for true newbies.

Link to comment
Share on other sites

Philosophically, I'm all for completeness. Even a brief statement about bitwise operators might reassure a programmer skilled in another language that they are available in javascript.But you also have to wonder how useful they are in a comparatively slow, interpreted environment. There are no DOM functions that involve bitmasking, for example. If you need to pass 8 Boolean values at once, I doubt you'd gain any useful speed or memory benefits using bits instead of bytes, especially when the typical JS function is so short-lived.I wonder if anyone's benchmarked that kind of thing.Just Some Guy was amazed a few months back when he finally encountered a useful application for a bitwise operator in javascript. It was his first one. Mine too, and I've never seen any others.Maybe I'm writing the wrong kind of apps. :)

Link to comment
Share on other sites

Hi, I am a newbie to JS and I was looking at the Tutorials for bitwise comparisons for a practice script. I noticed that JS Operators does not mention bitwise operators, and likewise neither does JS Comparisons. Something like if( x & 8 ). Other than that, I have already learned a lot just by reading the Tutorials and posts. Thanks for the great site. PS, I found what I needed on Google...just FYI. Thanks again.
OK so I used to design TTL logic circuits. My point was that W3Schools says it lists a complete reference. The first thing a person needs to know when learning a new language is what types of operators are available and what syntax should be used. That is pretty basic even if you don't have the slightest idea what a bitwise operator is or wheither it can be usefull.I wasn't suggesting that an explanation of what they are good for be included. If you apply that consideration to the tutorials, then a lot of them are lacking. On the contrary, they help me to learn the language... Actually, I was constructing a binary clock toy which you can find on my website. I figured I would start with some simple things first...
Link to comment
Share on other sites

Philosophically, I'm all for completeness. Even a brief statement about bitwise operators might reassure a programmer skilled in another language that they are available in javascript.But you also have to wonder how useful they are in a comparatively slow, interpreted environment. There are no DOM functions that involve bitmasking, for example. If you need to pass 8 Boolean values at once, I doubt you'd gain any useful speed or memory benefits using bits instead of bytes, especially when the typical JS function is so short-lived.I wonder if anyone's benchmarked that kind of thing.Just Some Guy was amazed a few months back when he finally encountered a useful application for a bitwise operator in javascript. It was his first one. Mine too, and I've never seen any others.Maybe I'm writing the wrong kind of apps. :)
How about something simple like determining if a value is even or odd?
 if ( value & 1 ){document.write( value + " is an odd number")}else{document.write( value + " is an even number" )}

Link to comment
Share on other sites

I've seen cases where bitwise operators can be 14 times faster and other times when it is a bit slower, it all depends.I have never used bitwise operators but some people like to maintain boolean variables with them, instead of having 8 different boolean variables you could have 8 bits in a single variable. That feels ugly to me but if you like that sort of thing I guess... IMO they make the code ahrder to read and when I have junior programmers with not much JavaScript experience it is easier for me to write clear code instead of having to explain it.

Link to comment
Share on other sites

I have never used bitwise operators but some people like to maintain boolean variables with them, instead of having 8 different boolean variables you could have 8 bits in a single variable.
20+ years ago it was standard, and if you programmed on a Mac in the 1990s, it was still part of the API for a LOT of things. It makes a lot of sense if you're tight on memory.
Link to comment
Share on other sites

I've seen cases where bitwise operators can be 14 times faster and other times when it is a bit slower, it all depends.I have never used bitwise operators but some people like to maintain boolean variables with them, instead of having 8 different boolean variables you could have 8 bits in a single variable. That feels ugly to me but if you like that sort of thing I guess... IMO they make the code ahrder to read and when I have junior programmers with not much JavaScript experience it is easier for me to write clear code instead of having to explain it.
Yes. In interpreted languages like BASIC and JS a bitwise comparison can be much faster and uses less code. As far as a practical use, how about checking the status of check boxes when validating a form post? This seems pretty basic to me, which is why bitwise comparisons should be included in the tutorials. How could this code be any clearer?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><HEAD><script language="JavaScript"><!--function showStatus(){status = "Status :";if( form.check1.checked ^ form.check2.checked ){status += " Only One Option is checked";}else if( form.check1.checked ){status += " All Options are checked";}else{status += "No Options are checked";}document.getElementById("output").innerHTML = status;}--></SCRIPT></HEAD><BODY><FORM name="form"><INPUT type="checkbox" id="check1"> Option 1<BR><INPUT type="checkbox" id="check2"> Option 2<BR><BR><BUTTON type="button" id="Button" onclick="showStatus()">Evaluate</BUTTON><BR><BR><DIV id="output"></DIV></FORM></BODY>

Link to comment
Share on other sites

  • 1 month later...

I agree that bitwise operators have a place in any Javascript reference. I would like to see w3schools remove the claim that their references are complete, however. Even a quick glance at the w3schools PHP reference vs. the official manual shows that w3schools is anything but complete. They might be doing a disservice to learners by claiming that their references are complete, when they should probably just explain that they're showing some of the more commonly-used things, and making people aware that they are leaving plenty out.

Link to comment
Share on other sites

  • 3 weeks later...
...They might be doing a disservice to learners by claiming that their references are complete, when they should probably just explain that they're showing some of the more commonly-used things, and making people aware that they are leaving plenty out.
I totally agree here with JustSomeGuy. I just joined a couple of months ago, and my experience was very much so similar to what JSG was sayin'. Here I am, needing to know Javascript, and so I come to this site, and BOOM! there's a complete reference for it. Now, as I continued (and still do continue) to learn these different languages and to use them for various, eclectic purposes, I realize how much is missing in these tutorials and references. Now, although W3Schools is my first stop when trying to learn something, most of the time, I end up having to delve for information elsewhere - or in the forums. The reason that W3's claim of completeness irked me is because I, at first, shut out the idea that there might be a method out there that would do what I needed it to do - I shut myself within the confines of W3Schools, assuming that their references were 'complete.' If you know that naive and green coders are going to be coming to this site, why confuse them with such a false statement? However, in the site's defense, any programmer should know that when some site or person claims to be 'complete' on a subject, or make some such similar claim, you should be instantly wary and critical of such a claim.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...