Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-16-2012, 09:18 PM   PM User | #1
Joyce137298
New to the CF scene

 
Join Date: Jun 2012
Location: New York, U.S.A.
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Joyce137298 is an unknown quantity at this point
Exclamation Hi guys some JavaScript examples?

Hi guys, i'm a newbie on coding and I just started learning it.
I learned that there are variables like "String", "Number" and "Boolean".
Can someone gimme examples fer each variables please this would help me alot.
Joyce137298 is offline   Reply With Quote
Old 06-16-2012, 10:08 PM   PM User | #2
Trickstar
New to the CF scene

 
Join Date: Jun 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Trickstar is an unknown quantity at this point
So you know what a comment is in JavaScript write? You must know in order to make it easier to read code, anything after "//" on one line is a comment and is not used as code. You said you were new to coding so I was just pointing that out in case you didn't know. But yep, heres your examples.

Code:
// The following line is a string
var bobIsCool = "Bob is cool"; // a string is contained in two quotation marks and cannot be handled in math expressions
// The following is a number (which can be either a floating point or an integer)
var exampleOfInteger = 2; // this was an integer
var exampleOfFloatingPoint = 1.3; // this was floating point
var trueFalse = true; // this is boolean, which is either true or false
Trickstar is offline   Reply With Quote
Old 06-16-2012, 10:15 PM   PM User | #3
Joyce137298
New to the CF scene

 
Join Date: Jun 2012
Location: New York, U.S.A.
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Joyce137298 is an unknown quantity at this point
Thank you for your help, and also thank you for the side informational, i didn't know that.
Joyce137298 is offline   Reply With Quote
Old 06-16-2012, 10:20 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
String, Number, and Boolean are actually objects in JavaScript - those examples provides are actually not String, Number, and Boolean - they are primitive strings, numbers, and booleans - which is completely different.

The objects with the same name (but the leading capital letter instead of lowercase) can be used to convert string, number, and boolean into String, Number and Boolean where in the case of the first two you then have a number of methods that can be applied - such as taking a substring of the String or converting the number to display with a fixed number of decimal places (not sure why anyone would ever use Boolean objects for anything) though).

For more information about the built in objects in JavaScript and the methods that they supply for manipulating your data see http://javascriptexample.net/objects.php
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
Joyce137298 (06-16-2012)
Old 06-16-2012, 10:29 PM   PM User | #5
Joyce137298
New to the CF scene

 
Join Date: Jun 2012
Location: New York, U.S.A.
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Joyce137298 is an unknown quantity at this point
Uhhh, i'm starting to get confused here. I tried the Java Script Sand box to practice some but when I copied some website page source information that was java script into the sand box, it had alot of errors.






This was the sandbox I used http://railsdotnext.com/experiment/jssandbox.html

The reason i'm getting into this stuff because i want to eventually code my own games with Unity Engine and on its website it said it supported JavaScript language. I figured this was the first step to creating games.

Last edited by Joyce137298; 06-16-2012 at 10:33 PM..
Joyce137298 is offline   Reply With Quote
Old 06-16-2012, 10:43 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Try this example. Maybe it will help clarify things:
Code:
<script type="text/javascript">

var s = new String( 33 ); 
var n = new Number( "713" ); 
var b = new Boolean( 3 > 5 ); 

document.write( typeof(s) + "::" + s + "<br/>");
document.write( typeof(n) + "::" + n + "<br/>" );
document.write( typeof(b) + "::" + b + "<br/>" );

s = String(33);
n = Number("731");
b = Boolean( 3 > 5 );

document.write( typeof(s) + "::" + s  + "<br/>");
document.write( typeof(n) + "::" + n  + "<br/>");
document.write( typeof(b) + "::" + b  + "<br/>");

s = "woof";
n = 3.1415;
b = 3 <= 7;

document.write( typeof(s) + "::" + s  + "<br/>");
document.write( typeof(n) + "::" + n  + "<br/>");
document.write( typeof(b) + "::" + b  + "<br/>");

</script>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 06-16-2012, 10:45 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
when I copied some website page source information that was java script into the sand box, it had alot of errors.
It is more than likely that the JS you copied was dependent on the HTML in the website page and, when you copied only the JS, it was trying to reference objects that didn't exist in the sand box.

HINT: You have a long road ahead of you.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:07 PM.


Advertisement
Log in to turn off these ads.