Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

JavaScript Variables, Types, Operators, and Expressions - 05

Download

Right click “Save as…”

Most programming languages have a notion of variables, data types, and syntax rules including statements, expressions, operators, keywords, and operands. In this video, Bob provides a quick overview of the most important topics related to basic syntax rules. He explains how JavaScript variables and types are different than those in other programming languages, explaining the purpose of "undefined." Finally, he shows how to use escape sequences in string literals.

Tag:

Follow the Discussion

  • PeterNLPeterNL

    Bob, IMHO you should had to stand back right now and start to declare and use separate javascript files. Much more everyday practice as one knows. Not overcomplicated at this point in the series I think.

  • @PeterNL: Hang in there ... it's coming soon ... Smiley

  • Ivan YosifovIvan Yosifov

    Just a quick remark, typeof IS a keyword.
    Best regards.

  • CKoenigCbrAInK Carsten

    BTW: in JS "values" got types not the variables - so if you put

    var myVar = "Hello";


    it's not myVar that will have any type - indeed you can just go on and give another value of a different type to the same variable without getting any complaints:

    var myVar = "Hello";
    myVar = 5;


    That is both one of the strenghts (as it gives you lot's of power - like duck-typing) but also one of the biggest weaknesses (as there is no compiler telling you about your type-errors) of dynamic languagues.

  • @CbrAInK: Great distinction!  Thank you ... I'm sorry if I confused this with my explanation.

  • @Ivan Yosifov: Thank you!

  • AnyonmousAnyonmous

    When you add myValue + myOtherValue you say 3.26 but it shows 6.26. Around 12:06 in the movie.

  • @Anyonmous: My mouth may have been talking faster than my brain was thinking.  Sorry for the confusion!

  • varunvarun

    Hi Bob..
    I am first time try Java Script.i am learning very fast. i am so much thankful to you for all this .you are simply great...

  • Hi Bob,

    you are explaining great, enjoying video tut. can i found something interesting  video tutorials like these all, for BOM (Browser Object Module) and DOM (Document Object Model) also. 

  • davedave

    Do u have these videos elsewhere? Ch9 is super slow for me. Sometimes takes me 30 mins to load the stream on a 500k/ba sec internet connection, and up to 45 min to download the low quality

  • @varun: Cool! Thanks for the note.

    @DharmendraSehgal: I'm not sure what you're asking.  But if you consider the BOM things like window and console, which technically are not part of the "document" per se, then I'm munging these two ideas together, as I think most authors do.  Technically, they probably need to be separated out, but hopefully that doesn't trip too many people up.

    @dave: Not yet, but I hope to add them to my site LearnVisualStudio.NET and stream from a bunch of different sources (Vimeo, YouTube, AmazonS3).

  • phetphet

    Great video on discussing variables and data types. Thank you!

  • DustierMantis5Dustier​Mantis5

    Thank you Bob for these great tutorials, but I hope you also upload ASP.NET tuts on Channel 9 for free :)

  • MohsinMohsin

    I was wondering when we do something like this.. what happens?
    var someValue;
    var myValue = "Hello";
    someValue = "\"World\"";
    someValue = myValue - someValue;
    alert(someValue);

  • @Mohsin:  Sorry to be coy here ... but ... this is a good chance for you to experiment!  Smiley  Tell me ... what happens?  

  • LarsLars

    Hi Bob, Beginner's Q: Why is it that we don't need an event to execute "alert" in your examples here in 05? In the Hello world an onload event is specified as the trigger for the "alert function" to execute, but here in 05 the alert runs without that call being used(?)

    Great series!

  • @Lars: Could you help me out by letting me know exactly where in the video you are referencing? A time marker like @5:15 (for example) would help refresh my memory so I could give you a better answer.  Thanks!

  • LarsLars

    Hi Bob, e.g. @2:50 in lesson 05 you write a script that results in an alert box being displayed (with the value "Jaworski") when it is tested in I.E. And that same script has not been called by an event (like "onload" or the user clicking a button)...it seems too me like the script runs once the page has been loaded, without the onload event being specified as necessary precursor for this to happen(?)
    In contrast in lesson 02 @13:27 you did use the onload event (specified in the body tag), and my Q is: Why is that not necessary in the example in 05?

    All the best,
    Lars :-)

  • Can I have a question?

    Why is this statement correct? I thought "var" is a keyword, and can't be used to name variable 

    if (var == 4) { // Do something }

    (you might feel it familiar, because I got it from one of your recommended books ^^)

  • @Minowar: Hi, I did this ... http://jsfiddle.net/Uvauc/ ... feel free to play around with it, then Save your own copy and show me the REST of that little code example.  Smiley  You shouldn't be able to do that little var trick ... at least, not with a modern web browser.  I would like to see that code at work, but I need to see what "var" is defined as ... how can it be created in the first place?  (In other words, I don't think that is a valid code example anymore.)  I've heard that once upon a time you can define false to another value, which can be confusing.  I've tried to duplicate that, but can't get it to work myself.  I'm guessing this is a similar case.  Let me know ... I'm curious to see what you come up with.

  • @Lars: I'm not sure quite how this is supposed to work ... I can merely demo it in a real case:

    http://jsfiddle.net/mpEDD/

    Follow the instructions ... see what happens when you remove the <body> tag from the HTML section.  Hint: you'll see the <script> part runs on load.  Weird.  And I'm not sure how to explain it, but that's the behavior.

  • LarsLars

    Ok, many thanks for your answer :-)

  • @BobTabor: Actually the statement didn't come from any code. It's an exercise from the book, and the question is the statement is valid or not. I looked at the key answer and it said the statement is valid.

  • @Minowar: Ok, you got me then.  Smiley  I tried to use 'var' as a variable, but couldn't get it to work.  Time to ask the author of the book ... then PLEASE let me know what he says.  Thanks and sorry I can't shed light on it.  According to everything I've seen, var is a keyword and can't be used as a variable name.  But what do I know?  Tongue Out

  • Hello Bob,

    I have seen some of your videos and i'm really impressed. I need a big favour from you. I need a javascript that will allow me display an XML file on my web page. We have an automation system that plays music. The "Title name" and "artist name" is contained in this XML file. what i want is for this information to be displayed on another system which contains my web page in the form of "Now playing". The info should also change each time a new track is played from the automation system i.e it should update with the current music/track playing with respect to the XML file info. The two systems are on the same Internet system. How do i go about this?

  • hi bob i'm really new to this, but i am learning fast with your video tutorial. But i have some question of which i already exhausted every possible article on the net that i can find, unfortunately i didn't. Hopefully you guys can help me out.

    in my own project where i tried to follow this video for the Additional Operator where I used text boxes to add all the value into another text box. for some reason it didn't add it, instead it concatenate the value. it doesn't have any problems with subtractions and multiplications only in additions. Below are the codes I've written for .js file

    function sumValue() {
         var sumValue = document.getElementById('number1').value;
         var sumval = document.getElementById('number2').value;
         var totaVal = (sumval + sumValue);
    
         document.getElementById('number3').value = totaVal;
    }

    here's my code for my HTML5 (which i also downloaded from you fundamental series.)

     <form method="post">
            <input type="number" id="number1"/>
            <input type="number"   id="number2"/>
            <input type="button" value="Sum" onclick="sumValue()"/> <br />
            <input type="text"  placeholder="Total" id="number3"/>
        </form>
        
    

     

    thanks in advance.

     

  • @kennethballon: The problem is that, by default in JavaScript, it treats all input as strings.  The + operator serves two purposes ... it will ADD numbers and CONCATENATE strings.  Since you didn't perform any data conversion from string to number, you're getting the concatenate behavior. Look for examples of the Javacript built-in function:

    parseInt()

    ... you'll need to use that first before adding numbers.

    And, before you treat them like numbers, you'll need to check to make sure those input strings CAN BE CONVERTED TO NUMBERS.  Use:

    isNaN()

    (NaN => Not a Number)

    Hope that helps!

  • @ Bob hahaha yah i remember the int.parse() in your video tutorial for C# Series,it just the other way around for JavaScript. Sometimes its hard to think straight when you're tired.... Anyways, it works and thank you so much for that.. i really love the way you explain things.

  • Mario CisnerosMario Cisneros

    @kennethballon,

    I've been racking my so called brain trying to figure-out the solution for the problem you initially posed. I read a few articles regarding the parseInt() built-in function and already knew about isNaN(), but no luck.

    Love to see your solution?

    Thank you,
    Mario

  • @Mario Cisneros:  Um ... it's been over a year since I recorded this video.  I honestly can't remember what problem I challenged you with.  I'm very sorry ... but could you point me to the time marker in the video (like @12:30 for example) where I issued the challenge?  I'll take a swing at it.  Smiley

  • Is this the link to the current JavaScript Language Specification. It seems to be. Just wanted to confirm.

    Thanks.

    http://www.ecma-international.org/publications/standards/Ecma-262.htm

  • @dsilvadarius: Yes, that looks good.  I think it's also known as ECMAScript 5.  There's also ECMAScript 6 on the horizon.  Here's a good link that will provide a list of features in ECMAScript 5 and the browsers that support each feature:

    http://kangax.github.io/es5-compat-table/

    There's also a link to ECMAScript 6 and it's compatibility as well (see top of page).  Good luck!

  • When browsing sample JavaScript code on the how do i know which version I'm reading.Is there an easy way to know that given that I've completed this series.

  • I forgot to say thanks earlier so thanks.

  • @dsilvadarius: How do you know which version of JavaScript a particular web page is using?  To my knowledge there's no way to say "I want to use version 5 of JavaScript" in code.  So, a a developer, you don't specify it, and fortunately, you never need to.  The client's web browser interprets the JavaScript and executes it.  If a particular developer uses a command that's not supported in an earlier version of JavaScript, the command will be ignored, and may possibly exit out of the code block.  As a developer, I would recommend using jQuery to smooth over the various versions of web browsers and stay away from the "latest greatest features of JavaScript".  Do some analysis on who you think your users will be and what browser versions they would use.  You will lose some, no doubt, to older browsers.  However, you can then target your code to address the majority of your potential users.  Hope that helps?

  • To be honest i thought this was a stupid question even thought of deleting it till I read the answer you gave. Thanks a lot.

  • There are other JavaScript libraries out there other than jquery right you don't even mention another  JavaScript library is there a particular reason for that or is it just a personal preference or Is it that jquery is that good.

  • @dsilvadarius: There are a lot of good libraries, however a few things.  (1) A few years ago Microsoft threw their full support behind jQuery, integrated syntax highlighting for jQuery into Visual Studio and more, (2) of the libraries out there that do similar things, I *think* jQuery is the most popular, and (3) we just don't have the time or money (budget) to create a comprehensive overview of all possibilities.  There are many libraries -- it seems like being the founder of a library is the new badge of honor for software developers -- and I personally want to focus on those that are already gaining traction.  I just don't have the time to invest in ones that no one will be interested in a few years from now.  Furthermore, jQuery is easy to learn and pretty darn fun, so it's a fit for this type of series.  Great questions, btw ... they challenge me and force me to really think about / justify the decisions we made.  Oh yeah, the fourth and best reason is: (4) Microsoft asked me to do it.  Big Smile

  • alert(typeof myValue);
    by it self also returns undefined if run.

  • @BobTabor: Jquery Mobile is built on top of the Jquery framework  Right? And its built on the notion of mobile first but can be use for all screen sizes right so I won't be fool to get a working knowledge of Jquery then dive directly into Jquery Mobile right? I wanted help with another thing t think its out side the scope of this series so I wont mind if you don't answer the question is how does one charge for a web site?  I've really struggled with this one. How do you do it you mind sharing? 

  • @dsilvadarius: Yes, I believe you're right on all accounts.  jQuery Mobile is a UI framework that defines user interface controls you can use (as well as animations, effects, etc.).  There's a "desktop" equivalent called jQuery UI (http://www.jqueryui.com).  If you're familiar with jQuery's syntax and such, I think it will be easy to roll your skills over into that framework.

    Regarding your second question about charging for websites, that's a toughie.  That's not what I do ... I started trying to do that way back in 1996 and was a little ahead of the curve.  Companies were asking "how do we get an email address?" and I was trying to sell dynamic database driven websites for eCommerce, etc.  I have a friend who runs http://www.learnwebdevelopment.com ... if you're serious about getting into web development for small to mid-sized companies, you might have a look there - the business side is his forte.

    If I work for a larger enterprise, it's usually as part of a team of developers, designers and ops, and usually I am hired on a contract basis through a consulting company or a contractor company.  They pay by the hour.  So, there are a lot of possible arrangements.  If you already have potential clients, perhaps you can approach them and express your desire to partner with them.  They may share with you other bids they've gotten or tell you how much they would be willing to spend.

  • Well why do the examples work for you? 

    None of the examples work as i see them in the videos. if i execute them no alert is executed :o

    i tested with ie chrome and firefox. But none of them is working :/

    Hmm do i need a special configuration for this?

  • @desmater: That's a good question ... I don't know.  Smiley  I suspect it could be one of several things.

    1. Which operating system are you using?  If you're using a SERVER operating system, there may be a permissions issue preventing you from saving HTML files to your desktop and executing them in Internet Explorer (or any web browser).  If you work at a large company, the computers may have been configured for you in such a way as to prevent potentially harmful activities.  Unfortunately, as a developer, you need to understand and undertake *potentially* harmful activities.  For these videos I think I used Windows 7 Pro and I was the administrator of that system, so there were no permissions problems for me.  Perhaps instead of saving to the desktop like I do in this video, try saving in your Documents directory.  Also, make sure you watch the previous videos where I allow active content. 

    Another option: upload to a free / cheap web server.  HTML files loaded locally have more permissions and are therefore deemed potentially more harmful than HTML files loaded from the internet.  This is the concept of "zones" in Internet Explorer.

    2. If you typed in the code examples yourself, you may have missed something small in your code.  Have you tried downloading the code and executing what I wrote just to make sure it works?  I assure you ... the code in those files is EXACTLY what I typed in while recording those videos.

    Did these help?  Still not able to get it working?  Please offer a few more details about your operating system, browser version, etc. and I'll try to help.

  • UmerNamdarUmerNamdar

    Hi Sir BOB! I completely watched your html5 and css3 series and now downloading this whole series. I just want to say thankyou for your great efforts. I have relly become your very big fan. :)

  • @UmerNamdar: Ah, cool.  Thanks for your support.  Smiley

  • RanjitRanjit

    Hi Bob,

    Very good explanation and enjoyed your video tutorial. You Rocks...

    Thanks a lot..

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.