SHARE

Hey ninjas. In today’s JavaScript tutorial, we’ll be taking a look at what variables are from a birds eye view. Variables are at the heart of most programming languages, and JavaScript is no different in that respect.

Variables area a way of storing information (such as the pixel position of an element on a page, or the customer name, or email) and can be of any of the main JavaScript types (integers, strings, boolean values etc – we’ll cover these later).

We need to use variables in our JS programs, so that we can refer to different pieces of varying information for different parts of our scripts to run! For example, an image slider needs to store how many images are in the slider.

As always, fire away with any questions :).

SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

========== JavaScript for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9i9Ae2D9Ee1RvylH38dKuET

========== CSS for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9gQeDH6xYhmO-db2mhoTSrT

========== HTML for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9ibZ2TSBaGGNrgh4ZgYE6Cc

========== The Net Ninja ============

For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk

========== Social Links ==========

Twitter – @TheNetNinja – https://twitter.com/thenetninjauk

16 COMMENTS

  1. Thanks for the tutorials! I like them.
    I have a question on this lecture: Why does it says "undefined" even though I assigned a value during variable declaration (var myVariable1 = 20;
    undefined)?

  2. Thanks man you really helping me out with my UDACITY course, when i am a rich devloper you will be repaid for your good work 🙂

  3. Net Ninja! Great energy! Your tuts are really fun to watch. I actually left a little question for you in tut38 of this series because that confused me. Could you please see if you can answer that? Also I have another little question please. I am trying to create an image slider( I have actually copied the code below). When I assign document.images part to the variable then my code wouldn't run. I can't work out why. Could you help? Thanks

    //this below code wouldn't work
    <body>
    <div><img src="image1.jpg" id="firstpic" alt="firstpic"></div>
    <script type="text/javascript">
    var imagecount=1;
    var x=document.images.namedItem("firstpic").src;
    function rotator(){
    if(imagecount<4){
    x="image"+imagecount+".jpg";
    imagecount++;
    }
    else{
    imagecount=1;
    }
    }
    setInterval(rotator,3000);

    </script>

    </body>

    //this below one works

    <body>
    <div><img src="image1.jpg" id="firstpic" alt="firstpic"></div>
    <script type="text/javascript">
    var imagecount=1;
    function rotator(){
    if(imagecount<4){
    document.images.namedItem("firstpic").src="image"+imagecount+".jpg";
    imagecount++;
    }
    else{
    imagecount=1;
    }
    }
    setInterval(rotator,3000);

    </script>

    </body>

  4. Another thing that could be done for the variable names if you're not intending to ever change their type would be to tack an abbreviation of what it should be onto the name, such as intFluffyKitten instead of fluffyKitten for an integer or strAppetizerChoice for a string. It gives a handy label for what data type it's intended to be.

    Of course, if you are intending on changing those variable's contents to a different type, that kinda tosses that out the window.

  5. Hey NetNinja; working through these vids while working on other platforms like Code Academy. Thank you so much for taking the time to make these.

LEAVE A REPLY

Please enter your comment!
Please enter your name here