Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Table of Contents D . 1 What is JavaScript? D . 2 Where do we link Scripts? D . 3 Types of Variables: D .
Table of Contents
D What is JavaScript?
D Where do we link Scripts?
D Types of Variables:
D Local Variables:
D Types of Variables:
D Making our first Script
D Function Parameters
D Creating our First Function
D Using a Library.
D What is JavaScript?
JavaScript is an interpreted computer programming language. As part of web browsers, implementations allow clientside scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed. It has also become common in serverside programming, game development and the creation of desktop applications. Interpreted programming languages get executed at run time while compiled languages get precompiled and then run. The advantage to compiled languages is that they are more powerful and can do heavier calculations.
JavaScript does have its advantages, however. JavaScript has the ability to run on any device or platform that runs a webbrowser which is pretty much any device with an internet connection JavaScript is almost standard across all platforms allowing developers to reuse the same code on any device rather than having to rewrite it when changing platforms.
By its nature, JavaScript is not an object oriented language. JavaScript is a functional language with the ability to create objects. This allows developers to create a sequence of commands without the steeper learning curves of an object oriented language and the overhead of creating objects in memory.
D Where do we link Scripts?
Most developers link their scripts at the head of their document, while I prefer to link mine at the bottom of the body. The reason being this holds true mostly for mobile the loading of scripts may slow down the rendering of HTML elements because it is linked before HTML elements appear in the document HTML documents read tags from the top of the document to the bottom By linking scripts at the bottom of the page, we allow the page and its styles tor load before we worry about loading the functionality of the page, ultimately enhancing the user experience.
D Types of Variables:
Variables
Variables are placeholders in memory that exist in every programming language. They give developers the ability to assign values to them dynamically without the developer knowing the actual value.
In JavaScript we can easily assign data to variables.
In this case we assign the first variable firstvar the string of hello Of course, this is not why we really use variables, especially if we know that we want to alert hello However, suppose we want to alert our user a value that we might not know.
For example, if we had an application where we wanted to display the users date when they clicked a button, it would be impossible for us to know the current date for all users at any given time. How do we solve this? We assign a variable in which we know the key to which would be a friendly name or address in which we can retrieve the value in storage and then use it at a later time. Take a look at the following:
As the developer, we know that we want to retrieve the date object for our user, but we do not know the actual time or value of that date. However, we do know that the variable mydate will represent the current date and time, so we can assign a date to it and use it in our function.If we alert mydate, it will tell us the current date and time.
D Local Variables:
Local variables are variables that are declared within a function and then erased from memory automatically when the function is complete. It is usually wise to declare a function locally because JavaScript deletes the function from memory and we no longer have to worry about it However, The drawback of having our variables deleted is that sometimes we need variables to persist until the user is finished using the application. In this case, using a local variable will not suffice.
D Global Variables:
Global variables have an application wide scope and are values that do not get deleted by JavaScript automatically they must be manually removed from memory However, unlike local variables, we only have to worry about assigning a value one time to our global variable.
For instance:
Since we know that our first name will always be the same, we should only have to declare that variable one time throughout our program. By doing this, we are able to allow multiple functions to utilize this variable without having to declare it again. Global variables do have drawbacks, however.
Any variable defined in the global name space owns that location in memory, so you will not be able to reuse the same variable name in memory again in any function.
JavaScript does not use garbage collection on global variables. If you have a lot of global variables, and do not manage your memory properly, your application starts to slow down noticeably.
The
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started