473,322 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Javascript test %4

I'm trying to understand some Javascript code from a certain site.
Could you please tell me what does this test mean?
if ( j%4 == 0 )
What does %4 test for and is there a web site that explains it and,
presumably, also %1, %2 etc.
Mar 7 '07 #1
8 2026
That's the modulo operator:
http://www.webdevelopersnotes.com/tu...operators.php3

Mar 7 '07 #2
Cogito said the following on 3/6/2007 11:52 PM:
I'm trying to understand some Javascript code from a certain site.
Could you please tell me what does this test mean?
if ( j%4 == 0 )
What does %4 test for and is there a web site that explains it and,
presumably, also %1, %2 etc.
The statement above means if the remainder of dividing j by 4 is 0.
You can change the 0 to anything smaller than j.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 7 '07 #3
Such quick replies. It's simply magic.
Thank you guys.
Mar 7 '07 #4
Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
Cogito said the following on 3/6/2007 11:52 PM:
>I'm trying to understand some Javascript code from a certain site.
Could you please tell me what does this test mean?
if ( j%4 == 0 )
What does %4 test for and is there a web site that explains it and,
presumably, also %1, %2 etc.

The statement above means if the remainder of dividing j by 4 is 0.
You can change the 0 to anything smaller than j.
There is no such limitation.

;-)

But to be useful:
Anything? Also any fraction or any negative integer?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 7 '07 #5
Evertjan. said the following on 3/7/2007 5:06 AM:
Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
>Cogito said the following on 3/6/2007 11:52 PM:
>>I'm trying to understand some Javascript code from a certain site.
Could you please tell me what does this test mean?
if ( j%4 == 0 )
What does %4 test for and is there a web site that explains it and,
presumably, also %1, %2 etc.
The statement above means if the remainder of dividing j by 4 is 0.
You can change the 0 to anything smaller than j.

There is no such limitation.

;-)
Tis true, but the results are pretty useles if k is smaller than j in j%k.
But to be useful:
Anything? Also any fraction or any negative integer?
Yes. Or at least testing doesn't throw up on fractions or negative
integers.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 7 '07 #6
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Wed, 7 Mar 2007 10:06:28, Evertjan. <ex**************@interxnl.net>
posted:
>Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
>Cogito said the following on 3/6/2007 11:52 PM:
>>I'm trying to understand some Javascript code from a certain site.
Could you please tell me what does this test mean?
if ( j%4 == 0 )
What does %4 test for and is there a web site that explains it and,
presumably, also %1, %2 etc.

The statement above means if the remainder of dividing j by 4 is 0.
You can change the 0 to anything smaller than j.

There is no such limitation.

;-)

But to be useful:
Anything? Also any fraction or any negative integer?
Yes, yes.

ISTM that, unless the code is an obfuscation of false, the right hand
side must be, or have a chance of being, smaller in absolute value than
the divisor is or may be. And, generally, all three values need to be
such as can be represented exactly by an IEEE Double, including NaN, if
the statement is to be reliably usable.

The OP could easily have answered his question by searching the PDF of
the Standards (FAQ cites one of them, IIRC) for "%".

The sections of the standards dealing with the % operator need
rewriting; at present, they use "floating-point" to mean "non-integer".
All Numbers are floating point currently.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 7 '07 #7
In comp.lang.javascript message <PZ********************@telcove.net>,
Wed, 7 Mar 2007 08:51:12, Randy Webb <Hi************@aol.composted:
>Evertjan. said the following on 3/7/2007 5:06 AM:
>Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
>>Cogito said the following on 3/6/2007 11:52 PM:
I'm trying to understand some Javascript code from a certain site.
Could you please tell me what does this test mean?
if ( j%4 == 0 )
What does %4 test for and is there a web site that explains it and,
presumably, also %1, %2 etc.
The statement above means if the remainder of dividing j by 4 is 0.
You can change the 0 to anything smaller than j.
There is no such limitation.
;-)

Tis true, but the results are pretty useles if k is smaller than j in j%k.
That is certainly not true, and neither is the converse. But if j is
*always* smaller than k, the operation is pointless.
>But to be useful: Anything? Also any fraction or any negative
integer?

Yes. Or at least testing doesn't throw up on fractions or negative
integers.
Testing has its uses; but the standards are sufficiently clear. For
example, -6.875%1.25 has a meaning, and the operation gives it.

--
(c) John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
In MS OE, choose Tools, Options, Send; select Plain Text for News and E-mail.
Don't quote more than is needed, and respond after each quoted part.
Mar 7 '07 #8
Dr J R Stockton said the following on 3/7/2007 11:48 AM:
In comp.lang.javascript message <PZ********************@telcove.net>,
Wed, 7 Mar 2007 08:51:12, Randy Webb <Hi************@aol.composted:
>Evertjan. said the following on 3/7/2007 5:06 AM:
>>Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
<snip>
>>But to be useful: Anything? Also any fraction or any negative
integer?
Yes. Or at least testing doesn't throw up on fractions or negative
integers.

Testing has its uses; but the standards are sufficiently clear. For
example, -6.875%1.25 has a meaning, and the operation gives it.
Yeah, the "standards" are sufficiently useless also. We all know how
abundantly clear the "standards" are with regards to toFixed() now don't we?

Keep the "standards", give me testing.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 8 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Mel | last post by:
if you know of dynamic expandable folder using CSS and display function, please drop me a note Yours, Mel
2
by: thinkfr33ly | last post by:
I have a page that inserts a block of javascript dynamically into the page "Test.html". The inserted block, "Block A", then does a document.write of another script block "Block B". This script...
15
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
7
by: e | last post by:
I've been having an extremely difficult time finding an answer to this in IE / js groups, so I thought I'd try here. I've got an aspx page that delivers loads of report data into custom-named...
2
by: duncan | last post by:
why does this work :- <HEAD> ...... <SCRIPT LANGUAGE="javascript"> function test() { alert("test 1") } </SCRIPT>
18
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. ...
3
by: WayneH | last post by:
Hi - I'm trying to use javascript to determine if a user's browser has cookies enabled or not. To test: copy this code into a file with a 'html' extension, and load it into your IE browser...
18
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
8
by: kerriejones | last post by:
I am trying to create a simple login routine, and am failing completely, I have tried to simplify the test and still no luck. HTML <form method="post" action="" > <div> <input...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.