Showing posts with label JAVASCRIPT English Version. Show all posts
Showing posts with label JAVASCRIPT English Version. Show all posts

Thursday, February 14, 2019

Know Your Dialog Window in Javascript Programming

Know Your Dialog Window in Javascript Programming
In the earlier material , you've learned how to display the output on Javascript programming.

One of them is by using the function alert () . Function alert () is a function that can show both output in the dialog window.

Before issuing the output must be input, there are two ways we can do to take inputs:
  • The first way: Using form.
  • The second method: Using the dialog window.

In this matter we will discuss the second way is by using the dialog window.

Dialog window is a window that can be used to interact with the user.

There are three kinds of dialog window in Javascript:
  • Dialog window alert () ;
  • Dialog window confirm () ;
  • Dialog window prompt () ;

The dialogue has a different way and use each.

Let's discuss them one by one.

Alert Dialog Window

Dialog alert () is usually used to display a warning message or information that appears in a pop-up browser.

Function alert () within the window object.

We can write fatherly can use it like this:
window.alert("Learn Javascript FajarYusuf.com");
Or like this:
alert("Learn Javascript FajarYusuf.com");
Since the beginning of the window object is an object that global backwardly, we can not write it.

Dialog alert () will not return any value when executed.

Please try the following code, you may write to create a .html file, or it can be run through HTML editor FajarYusuf.com :

<!DOCTYPE html>
<html>
     <head>
         <title> Example Dialog Alert </title>
     </head>
     <body>
     <script>
         alert ("Welcome to the FajarYusuf.Com Javascript tutorial");
     </script>
     </body>
</html>


The result:
Know Your Dialog Window in Javascript Programming

Dialog alert () has loaded parameter above should be given in the form of text to be displayed in the dialog that appears in a pop-up window.

In the above example, we give the text "Welcome to the FajarYusuf.Com  Javascript tutorial".

And if you ask how to display a dialog alert () on certain events, for example on a click event or when a button is clicked?

This can be done by adding a dialog function in the event listener.

In HTML, we can put the function alert () on the attribute onclickso that it will be displayed when an element present in the onclick clicked.

Coding example:

<!DOCTYPE html>
<html>
    <head>
        <title>Belajar Dialog Alert</title>
    </head>
    <body>
        <button onClick="alert('Kamu sudah menekan Tombolnya!')">Klik Ini</button>
    </body>
</html>


The result:
Know Your Dialog Window in Javascript Programming
Dialog window of alerts will appear when the button is clicked


Confirm Dialog Window

Dialog confirm ()  is needed to confirm the specific action.

For example, when we approve something going action we take, it will be better if we show the dialog confirm () . Because if no such action would be dangerous.

Dialogue can be made to confirm the function confirm () .

Writing Sample:
confirm ( "Are you sure you want to delete your status?");
Dialogue confirm () will return true when we choose the OK button and returns a false value when we choose Cancel.

This return value can be disposed within the variable to be processed.

Example code:

<!DOCTYPE html>
<html>
     <head>
         <title> Learning Confirm Dialog </title>
     </head>
     <body>
     <script>
         var sure = confirm ("Are you sure you want to go to the FajarYusuf.Com main page?");
         if (sure) {
             window.location = "https://www.fajaryusuf.com";
         } else {
             document.write ("Ok, you still want it here :)");
         }
     </script>
     </body>
</html>


The result:
Know Your Dialog Window in Javascript Programming

Prompt Dialog Window

Dialog prompt ()  usually serves to take an input from the user.

Dialog prompt () will return a string value of what was entered by the user.

Example code:
<!DOCTYPE html>
<html>
    <head>
        <title>Learning Dialog Promp</title>
    </head>
    <body>
    <script>
        var name = prompt("Hello who are you?", "");
        document.write("<p>Hello "+ name +"</p>");
    </script>
    </body>
</html>


The result:
Know Your Dialog Window in Javascript Programming


Dialog prompt () has two requirements for parameters that must be given:

  • Text to be displayed on the form.
  • The default value for the input field.
In the coding example above, we provide its default value is an empty string in quotation marks "".


Conclusion


When is the right time to use Dialogue Alert, Confirm, and Prompt?
Based on the examples that have been described above, we can know when it is appropriate to use the alert (), confirm () and prompt ().

When we only want to display information without expecting something in return users, then use the alert ().

When we want to get the answer confirmation from the user, then use confirm ().

And when we want to retrieve data from the user input text, then use the prompt ().

Sunday, February 10, 2019

Variables and Data Types In Javascript Programming

Variables and Data Types In Javascript Programming

Variables and Data Types are two basic things in a programming language is always used, and these two things will always exist in any programming language.

What definition of variables?

variable is the name that represents the value. Variables can be filled with a wide variety of grades with different types of data, such as strings (text), number (digit), objects, arrays, and others.

If compared with an object, then that variable as a container for storing things.

Variables and Data Types In Javascript Programming

On this matter we will learn about variables and data types that are in Javascript.

We'll start on the way to create a variable, how to print a variable to output, recharge, and remove it from memory.


How to Create Variables in Javascript

How to create a variable that is commonly used on javascript programming is to use the keyword var followed by a variable name and its value.

Example code:
var title = "Learning Javascript on FajarYusuf.Com ";
In the coding example above, we create a variable named title with a value in the form of text string data type: "Learning Javascript on FajarYusuf.Com ".

Furthermore example code:

var webName = "FajarYusuf.Com";
var url = "https://www.FajarYusuf.com";
var visitorCount = 1404; 

In the example above, we use letters to major variable names consisting of two syllables.

Underscore why we do not use it?

As we Javascript programming is more advisable to use camelCase in naming variables. 
Variables and Data Types In Javascript Programming
If we can not use camelCase? , Can only use a case or underscore snake like this example:
var web_name= "FajarYusuf.Com";
var visitor_count = 1404;
It will not be a problem or error coding, the program will remain valid and may be in the running. However, the majority of Javascript programmers prefer to use camelCase.

According to your taste, want to join the camelCase majority or snake_case minority.

It is necessary to note also, in addition to using the keyword var can also create a variable with the keyword let or without any keywords .

Example code:
// create a variable with the keyword let 
let price = 14000;
// create a variable without any keyword 
stock = 12
What is the difference between the three ways that using var, let and without the keyword?

The difference lies in the reach and use. Will be discussed more deeply.

Other questions might be:
"What happens if the value of the variable is not filled?"

The answer, it would be worth undefined variables (undetermined).

Example :
var x;
Then the variable x will be worth undefined.

How to display the contents of variables Javascript

How to display the contents of variables, we can use existing functions for output like the following:
  • The function console.log () output to the console javascript;
  • Function document.write () output to the HTML document;
  • and Function alert () output to the dialog window.

Let's try it, create a file called learning-variabel.html, then fill with the code below, or you can also try the html editor fajaryusuf.com   HERE  :

<html lang="en">
<head>
    <title>Belajar Variabel Javascript di FajarYusuf.Com</title>
    <script>
        // membuat variabel
        var name = "FajarYusuf.Com";
        var visitorCount = 1404;
        var isActive = true;
        var url = "https://www.fajaryusuf.com";
        // menampilkan variabel ke jendela dialog (alert)
        alert("Selamat datang di " + name);
        // menampilkan variabel ke dalam HTML
        document.write("Nama Situs: " + name + "<br>");
        document.write("Jumlah Pengunjung: " + visitorCount + "<br>");
        document.write("Status Aktif: " + isActive + "<br>");
        document.write("Alamat URL: " + url + "<br>");
    </script>
</head>
<body>
</body>
</html>



The result:
Variables and Data Types In Javascript Programming

The meaning of the plus symbol ( + ) in the above example is to combine, not to add up.

How to Charge Changing the Content of Variables

Variables are mutable, meaning that the value stored in it can be refilled or changed.

Example code :

// first we create a variable with the contents of this early 
var age = 25; 
// then we change it 
age = 17;
Why when recharging or change the value of the variable does not use the var keyword?

Because the var keyword is required when creating a variable. As for recharge, we just write as above.

If we use the var keyword, meaning it can be interpreted we create a new variable, not recharge or change the value.

How to Delete Variable

Elimination of variables in javascript is rarely done. However, for programs that require precision in memory allocation, elimination of variables necessary for optimal memory usage and can be controlled.

Elimination of variables can be done with the keyword delete.

Example code:
title = "Javascript Programming Study In FajarYusuf.Com "; 
delete title;
Then the variable title will be erased from memory.

Elimination of variables can only be performed on variables that are made without the prefix keyword. While the variables created with the keyword var and let will be deleted automatically.

What Is a Data Type

The data type is various types of data that we can use in variable to specify the data type of the value.

There are several types of data in Javascript programming:

  • String (text)
  • Integer or Number (integer)
  • Float (number fraction)
  • Boolean
  • Object
Javascript is a language that is dynamic typing , meaning we do not have to write or specify the data types when creating variables. Unlike in C, C ++, Java, etc is static typing .

Example code:
var name = "Eka";
var age = 24;
var single = false;
Javascript will automatically identify the type of data that we give to each variable by value.

In the above example, we would get the following:

  • String data type name;
  • age integer data type;
  • and single boolean data type.
For certain things from these data types we can also check with the keyword typeof .

Example code:
typeof name;
typeof age;
typeof single;

The results on the console:
Variables and Data Types In Javascript Programming
How we can identify the type of data on javascript in addition to using typeof?

We can recognize by way of writing.

Example code:
// for text or string data type of writing is always enclosed in quotation marks 
var author = "Fajar Yusuf"; 
// while the number and Boolean data types are not enclosed in quotation marks 
var available = true; // for data type boolean only true and false 
var total = 25;


Rules For Writing Variable Name in Javascript

There are a few rules of writing variables in Javascript:

The first rule: Naming variables can not use the numbers in front of .

example code:
// wrong
var 123name = "FajarYusuf.Com";
   
// right
var name123 = "FajarYusuf.Com";
Rule Two: Naming variables can use the initial underscore.

coding examples:
var _name = "FajarYusuf.Com";
Third rule: Naming variables when recommended use CamelCase consisting of two syllables.

Coding example:

var webName = "FajarYusuf.Com";
Fourth rule: Naming variables is recommended to use English

Example code:

var postTitle = "Tutorial Javascript on FajarYusuf.Com";

TENTANG SITUS

SITUS INI ADALAH SITUS PEMBELAJARAN PEMROGRAMAN DAN JUGA PEMAHAMAN TERHADAP TEKNOLOGI KOMPUTER. KALIAN BISA MENGIKUTI PEMBELAJARAN PEMROGRAMAN DENGAN BERTAHAP PADA MATERI YANG SUDAH SAYA SEDIAKAN, JIKA ADA MATERI YANG MEMBINGUNGKAN SILAKAN LAKUKAN KOMENTAR PADA MATERI YANG ANDA TANYAKAN ATAU KALIAN BISA MENGHUBUNGI SAYA DIHALAMAN KONTAK.

https://smallseotools.com/