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

Embed code for this video

Copy the code above to embed our video on your website/blog.

Close

Video format

Option selected may change based on video formats available and browser capability.

Close

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

Remove this comment

Remove this thread

close

Comment on the Post

Already have a Channel 9 account? Please sign in