- Browser Application Programming Interfaces (APIs) — APIs built into web browsers, providing functionality like dynamically creating HTML and setting CSS styles, collecting and manipulating a video stream from the user’s webcam, or generating 3D graphics and audio samples.
- Third-party APIs to allow developers to incorporate functionality in their sites from other content providers, such as Twitter or Facebook.
- Third-party frameworks and libraries you can apply to your HTML to allow you to rapidly build up sites and applications.
Everyone knows about var. To declare a variable, you need to use the var keyword and provide that variable a name.
(Hopefully something that makes sense)
let is introduced in ES6 (ES2015 ). This gave us another way to define variables that can be reassigned, and are block scoped.
Unique Let Names
You cannot re-declare a variable using the let keyword. It will throw an error and crash your app.
const is also a new way to define variables, cannot be reassigned, and are block scoped.
const is MUTABLE
const values cannot be reassigned or redeclared. But, you can mutate the data that is in it.
const must be initialized.
Since const cannot be reassigned, it must hold a value when it is first being declared.
Global vs. Local
Scope determines the accessibility, or visibility, of variables and functions.
Variables defined within a function is called a “local” variable. If you try to access that variable anywhere else other than that function, you will get an error.
Variables defined outside a function is called a “global” variable. You can access this variable from anywhere in your code.
These can be used as standalone variables or as part of function parameters.
A “hello world” example
- First, go to your test site and create a new folder named ‘scripts’ (without the quotes). Then, within the new scripts folder you just created, create a new file called js. Save it in your scriptsfolder.
- Next, in your htmlfile enter the following element on a new line just before the closing </body> tag:
- Now add the following code to the jsfile:
- var myHeading = document.querySelector(‘h1’);
myHeading.textContent = ‘Hello world!’;
After that, you set the value of the myHeading variable’s textContent property (which represents the content of the heading) to “Hello world!”.
Note: Both of the features you used above are parts of the Document Object Model (DOM) API, which allows you to manipulate documents.
Feel the love for programming? Become a Web Developer in less than a year and join one of the fastest, growing professions in the planet here