itwiz55 Posted January 31, 2006 Share Posted January 31, 2006 All I know is that we are declaring a variable called maxX, and whatever is inside the brackets is called a condition. But I want explained to me what exactly the condition is. Please refer to the following snippet:var maxX = (document.all ? parseInt(document.body.offsetWidth) : parseInt(window.innerWidth)) - 50;Regards,Lucca. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 31, 2006 Share Posted January 31, 2006 the snippet you have could also be written this way var maxX;if(document.all) maxX = parseInt(document.body.offsetWidth)else maxX = parseInt(window.innerWidth)) - 50; Basically using the ? shortens the code. Let me explain.(document.all ?) means is document.all a valid object/condition?parseInt(document.body.offsetWidth) : parseInt(window.innerWidth)) - 50; means yes : no so if document.all is valid then maxX = parseInt(document.body.offsetWidth) else it equals parseInt(window.innerWidth)) - 50. The other way I wrote it above takes up more lines of code but is easier to understand. The snippet you have is just optimized for minimal lines of code. They both do the same thing. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now