Blog Firman Santosa
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
  • Men
  • Women
Tidak ada hasil
Tampilkan semua hasil
Blog Firman Santosa
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
  • Men
  • Women
Tidak ada hasil
Tampilkan semua hasil
Blog Firman Santosa
Tidak ada hasil
Tampilkan semua hasil

Memahami Javascript Output, Statement, Syntax dan Comments

Penjelasan lengkap Output, Statement, Syntax dan Comments Pada Javascript

Firman Santosa Oleh Firman Santosa
Juni 3, 2020
di Javascript
78 0
50
Memahami Javascript Output, Statement, Syntax dan Comments

Memahami Javascript Output, Statement, Syntax dan Comments

Share on FacebookShare on Twitter

Hai programmmer… Kali ini kita akan melanjutkan pembahasan kita sebelumnya tentang Pengenalan Javascript Lengkap. Silahkan dibaca terlebih dahulu karena artikel ini sangat berkaitan dengan artikel pembelajaran javascript part-1 sebelumnya. Kita akan coba memahami apa itu javascript output, statement, syntax juga comment, sehingga nantinya kita akan lebih mudah lagi memahami materi selanjutnya tentang Tutorial Javascript Indonesia.

Artikel pembelajaran kali ini sudah saya buat terpisah dengan harapan memudahkan kita memahami dasar-dasar javascript yang wajib kita ketahui. Silahkan anda simak dan perhatikan dengan seksama pembahasan javascript di bawah ini yang menjelaskan tentang Output, Statement, Syntax dan Comments pada javascript.

Javascript Output

Javascript dapat menampilkan data dengan bebagai cara, ialah sebagai berikut :

  1. Menulis menjadi elemen HTML, menggunakan innerHTML.
  2. Menulis ke dalam output HTML menggunakan document.write().
  3. Menulis ke dalam kotak peringatan, menggunakan window.alert().
  4. Menulis ke konsol browser, menggunakan console.log().

Masih bingung? akan saya jelaskan satu persatu.

1. Menggunakan innerHTML

Untuk mengakses elemen HTML, JavaScript dapat menggunakan metode document.getElementById(id). Atribut id mendefinisikan elemen HTML. Properti innerHTML mendefinisikan konten HTML. Perhatikan contoh di bawah ini.

<!DOCTYPE html>
<html>
<body>

<h1>Percobaan Pertama</h1>
<p>Halaman percobaan pertama</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>

</body>
</html>

2. Menggunakan document.write()

Sebenarnya, saat kita sedang developing aplikasi, lebih mudah menggunakan document.write() saat pengkodean aplikasi kita untuk debuging. Perhatikan contoh berikut ini.

Contoh pertama :

<!DOCTYPE html>
<html>
<body>

<h1>Halaman pertama saya</h1>
<p>Halaman pertama saya.</p>

<script>
document.write(5 + 6);
</script>

</body>
</html>

Contoh kedua :

<!DOCTYPE html>
<html>
<body>

<h1>Halaman saya</h1>
<p>Halman saya</p>

<button type="button" onclick="document.write(5 + 6)">Coba</button>

</body>
</html>

penggunaan document.write() sebaiknya digunakan hanya untuk kebutuhan testing.

3. Menggunakan window.alert()

Anda juga bisa menggunakan window.alert() untuk menampilkan data. Perhatikan contoh berikut.

<script>
window.alert(5 + 6);
</script>

Juga anda bisa menghilangkan window saat untuk menampilkan alert. Dalam JavaScript, alert adalah objek lingkup global, yang berarti bahwa variabel, properti, dan metode secara default adalah milik si alert. Ini juga berarti bahwa menggunakan sintax window adalah opsional. Perhatikan contoh berikut :

<script>
alert(5 + 6);
</script>

4. Menggunakan console.log()

Saat anda developing, anda bisa menggunakan console.log() untuk debugging sehingga bisa menampilkan data pada browser. Perhatikan contoh berikut ini :

<!DOCTYPE html>
<html>
<body>

<script>
console.log(5 + 6);
</script>

</body>
</html>

Javascript Statements (Pernyataan Javascript)

Javascript Statements (Pernyataan JavaScript) terdiri dari Values, Operators, Expressions, Keywords, dan Comments.

Sebagian besar program JavaScript berisi banyak pernyataan JavaScript. Pernyataan dieksekusi, satu per satu, dalam urutan yang sama seperti yang tertulis. Penjelasan tentang Javascript Statements ini saya buat terpisah agar memudahkan kita mempelajari bagian-bagian dari Pernyataan Javascript tersebut.

1. Semicolons (Titik Koma)

Titik koma memisahkan pernyataan JavaScript. Tambahkan tanda titik koma di akhir setiap pernyataan yang dapat dieksekusi:

var a, b, c;     // menyatakan 3 variable
a = 5;           // menetapkan nilai a adalah 5
b = 6;           // menetapkan nilai b adalah 6
c = a + b;       // menetapkan menjumlahan antara a dan b

Ketika dipisahkan oleh titik koma, beberapa pernyataan pada satu baris juga diperbolehkan. Perhatikan contoh berikut :

 a = 5; b = 6; c = a + b;

2. Javascript Code Blocks

Pernyataan JavaScript dapat dikelompokkan bersama dalam blok kode, di dalam kurung keriting {…}. Tujuan dari blok kode adalah untuk mendefinisikan pernyataan yang akan dieksekusi bersama. Beberapa penggunaan pada penerapan ini, anda terkadang akan menemukan pernyataan yang dikelompokkan bersama dalam blok, dalam fungsi JavaScript tersebut. Lihat contoh berikut :

function myFunction() {
  document.getElementById("demo1").innerHTML = "Hai wak!";
  document.getElementById("demo2").innerHTML = "Sehat kan?";
}

3. Javascript Keyword

Pernyataan JavaScript sering dimulai dengan keyword untuk mengidentifikasi tindakan JavaScript yang harus dilakukan. Berikut adalah daftar beberapa keyword yang dapat anda pelajari di tutorial kali ini.

Keyword Description
break Mengakhiri switch atau loop (perulangan)
continue Melompat keluar dari lingkaran dan mulai di atas
debugger Menghentikan eksekusi JavaScript, dan memanggil (jika ada) fungsi debugging
do … while Mengeksekusi blok pernyataan, dan mengulangi blok, sementara kondisi benar
for Menandai blok pernyataan yang akan dieksekusi, selama syaratnya benar
function Deklarasi function
if … else Menandai blok pernyataan yang akan dieksekusi, tergantung pada suatu kondisi
return Exits a function
switch Menandai blok pernyataan yang akan dieksekusi, tergantung pada kasus yang berbeda
try … catch Menerapkan penanganan kesalahan pada blok pernyataan
var Deklarasi variable

Javascript Syntax

Sintaks JavaScript mendefinisikan dua jenis nilai: Nilai tetap dan nilai variabel. Nilai tetap disebut literal. Nilai variabel disebut variabel.

1. JavaScript Literals

Aturan paling penting untuk menulis nilai tetap adalah:

Angka ditulis dengan atau tanpa desimal:

10.50

1001

String adalah teks, ditulis dalam tanda kutip ganda atau tunggal:

"John Doe"

'John Doe'

2. JavaScript Variables

Dalam bahasa pemrograman, variabel digunakan untuk menyimpan nilai data. JavaScript menggunakan kata kunci var untuk mendeklarasikan variabel. Tanda yang sama juga digunakan untuk menetapkan nilai ke variabel.

Dalam contoh ini, x didefinisikan sebagai variabel. Kemudian, x diberikan (diberi) nilai 6 :

var x;

x = 6;

Javascript Comments (Komentar pada Javascript)

Komentar JavaScript dapat digunakan untuk menjelaskan kode JavaScript, dan membuatnya lebih mudah dibaca. Komentar JavaScript juga dapat digunakan untuk mencegah eksekusi, saat menguji kode alternatif.

1. Single Line Comments

Komentar satu baris dimulai dengan //. Teks apa pun antara // dan akhir baris akan diabaikan oleh JavaScript (tidak akan dieksekusi).

Contoh ini menggunakan komentar satu baris sebelum setiap baris kode :

// Ganti heading:
document.getElementById("myH").innerHTML = "Halaman Pertamo";

// Ganti paragraf:
document.getElementById("myP").innerHTML = "Halaman pertamo saya.";

Contoh ini menggunakan komentar satu baris di akhir setiap baris untuk menjelaskan kode :

 var x = 5;      // Deklarasi x, memberikannya nilai 5
var y = x + 2;  // Deklarasi y, memberikannya nilai x + 2

2. Multi-line Comments

Komentar multi-baris dimulai dengan /* dan diakhiri dengan */.

Teks apa pun antara /* dan */ akan diabaikan oleh JavaScript.

Contoh ini menggunakan komentar multi-baris (blok komentar) untuk menjelaskan kode:

/*
Contoh kode ini dan itu
Menampilkan data komentar
hanya terlihat di dalam kodingan
*/
document.getElementById("myH").innerHTML = "Halaman saya";
document.getElementById("myP").innerHTML = "Halaman kita semua.";

3. Menggunakan Komentar untuk Mencegah Eksekusi

Menggunakan komentar untuk mencegah eksekusi kode cocok untuk pengujian kode. Menambahkan // di depan baris kode mengubah baris kode dari baris yang dapat dieksekusi ke komentar.

Contoh ini menggunakan // untuk mencegah eksekusi salah satu baris kode :

//document.getElementById("myH").innerHTML = "Halaman Gendeng";
document.getElementById("myP").innerHTML = "Halaman Waw mantapu.";

Contoh ini menggunakan blok komentar untuk mencegah eksekusi beberapa baris :

/*
document.getElementById("myH").innerHTML = "Halaman gendeng";
document.getElementById("myP").innerHTML = "Halaman Waw mantapu.";
*/

Semoga artikel ini bermanfaat untuk memahami dasar-dasar yang wajib anda ketahui sebelum melanjutkan pembelajaran javascript lebih lengkap. Silahkan beri komentar anda jika terdapat hal-hal yang belum anda mengerti.

Tags: Javascript

TerkaitArtikel

Pengertian Javascript - Tutorial Javascript
Javascript

Pengenalan Javascript Lengkap

Pengertian Javascript Pengenalan Javascript Lengkap - JavaScript adalah bahasa skrip sisi klien yang sangat kuat. JavaScript digunakan terutama untuk...

Oleh Firman Santosa
April 3, 2020
Artikel Selanjutya
Java NetBeans 12.0 Tutorial

(POS Part -1) Membuat Login Java Dengan MySQL Menggunakan NetBeans IDE 12.0

Diskusi 50

  1. fafa slot says:
    2 tahun yang lalu

    I have read so many content about the blogger lovers except this
    piece of writing is actually a fastidious paragraph, keep it up.

    Balas
  2. jokerslot says:
    2 tahun yang lalu

    I think this is one of the most vital info for me. And
    i am glad reading your article. But wanna remark on few general things, The website style is wonderful, the articles is really nice : D.
    Good job, cheers

    Balas
  3. Slot Gacor QQkini says:
    2 tahun yang lalu

    magnificent points altogether, you simply won a new reader.
    What could you suggest in regards to your publish that you made some
    days in the past? Any sure?

    Balas
  4. Slot Gacor Royalgacor says:
    2 tahun yang lalu

    Valuable information. Lucky me I found your web site accidentally, and I am shocked why this twist of
    fate did not came about earlier! I bookmarked it.

    Balas
  5. Royal Gacor says:
    2 tahun yang lalu

    Very great post. I just stumbled upon your blog and wished to say that I’ve truly
    enjoyed surfing around your weblog posts. After all I’ll be subscribing in your feed
    and I’m hoping you write again soon!

    Balas
  6. medtronic cgm sensor says:
    2 tahun yang lalu

    Awesome article.

    Balas
  7. is salt bad for dogs says:
    2 tahun yang lalu

    I really like it whenever people come together and share views.
    Great website, stick with it!

    Balas
  8. garuda138 slot gacor says:
    2 tahun yang lalu

    Hi, i read your blog occasionally and i own a similar one
    and i was just curious if you get a lot of spam responses?
    If so how do you protect against it, any plugin or anything you can advise?
    I get so much lately it’s driving me insane so any help is very much appreciated.

    Balas
  9. royal gacor says:
    2 tahun yang lalu

    This piece of writing will assist the internet people for creating new blog or even a weblog
    from start to end.

    Balas
  10. 먹튀검증 says:
    2 tahun yang lalu

    Hi, all is going well here and ofcourse every one is sharing facts,
    that’s in fact good, keep up writing.

    Balas
  11. 먹튀검증 says:
    2 tahun yang lalu

    excellent submit, very informative. I wonder why the opposite specialists of this sector
    do not understand this. You should proceed your writing.

    I am confident, you have a great readers’ base already!

    Balas
  12. vivoslot says:
    2 tahun yang lalu

    My programmer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses.

    But he’s tryiong none the less. I’ve been using
    Movable-type on several websites for about a year and am anxious about
    switching to another platform. I have heard very good things about blogengine.net.
    Is there a way I can transfer all my wordpress content
    into it? Any kind of help would be really appreciated!

    Balas
  13. vivoslot says:
    2 tahun yang lalu

    Good way of describing, and fastidious article to take information concerning my presentation subject matter, which i am going to deliver
    in academy.

    Balas
  14. sbo-bet.co.com says:
    2 tahun yang lalu

    I like it when individuals get together and share ideas.

    Great website, continue the good work!

    Balas
  15. sv-388.com.co says:
    2 tahun yang lalu

    It’s awesome in support of me to have a web page, which is
    good in favor of my knowledge. thanks admin

    Balas
  16. fafaslot says:
    2 tahun yang lalu

    Hi, its pleasant piece of writing about media print, we
    all know media is a fantastic source of data.

    Balas
  17. slot77 says:
    2 tahun yang lalu

    Wow, superb blog layout! How long have you been blogging for?

    you made blogging look easy. The overall look of your web site is excellent, let
    alone the content!

    Balas
  18. sbo-bet.co says:
    2 tahun yang lalu

    If you are going for most excellent contents like I do, simply pay a visit this web page all
    the time since it provides feature contents, thanks

    Balas
  19. sbobet88-online.com says:
    2 tahun yang lalu

    This is a topic that’s close to my heart… Many thanks!
    Exactly where are your contact details though?

    Balas
  20. Tredsafe Shoes Around World says:
    2 tahun yang lalu

    Heya just wanted to give you a brief heads up and let you know a few of the pictures
    aren’t loading correctly. I’m not sure why but
    I think its a linking issue. I’ve tried it
    in two different browsers and both show the same results.

    Balas
  21. joker slot says:
    2 tahun yang lalu

    What’s Happening i am new to this, I stumbled upon this I have discovered It absolutely useful and it
    has helped me out loads. I hope to contribute & assist other users like its
    helped me. Great job.

    Balas
  22. gacor slot says:
    2 tahun yang lalu

    I have been browsing online more than three hours today, yet I never found any interesting article like yours.
    It’s pretty worth enough for me. Personally, if all web owners and bloggers made good content as you
    did, the internet will be much more useful than ever before.

    Balas
  23. fafaslot says:
    2 tahun yang lalu

    This post offers clear idea in favor of the new users of blogging, that in fact
    how to do blogging and site-building.

    Balas
  24. vivo slot says:
    2 tahun yang lalu

    Good day! I know this is kinda off topic but I was wondering
    which blog platform are you using for this website?
    I’m getting sick and tired of WordPress because
    I’ve had issues with hackers and I’m looking at options for
    another platform. I would be great if you could point me in the direction of
    a good platform.

    Balas
  25. ETB pokemon says:
    2 tahun yang lalu

    Superb site you have here but I was wanting to know if
    you knew of any user discussion forums that cover the same topics
    talked about in this article? I’d really love
    to be a part of online community where I can get feedback from other knowledgeable people that share the same
    interest. If you have any suggestions, please let me know.

    Thanks!

    Balas
  26. jokerslot says:
    2 tahun yang lalu

    Hi there, You have done an excellent job. I will
    definitely digg it and personally suggest to my friends.
    I am confident they’ll be benefited from this website.

    Balas
  27. daftar viva99 says:
    2 tahun yang lalu

    What’s up, its fastidious article on the topic
    of media print, we all understand media is a impressive
    source of facts.

    Balas
  28. carpenter says:
    2 tahun yang lalu

    This paragraph provides clear idea designed for the new visitors of blogging,
    that truly how to do blogging.

    Balas
  29. vivoslot says:
    2 tahun yang lalu

    I was able to find good advice from your content.

    Balas
  30. See Details says:
    2 tahun yang lalu

    Hello my family member! I want to say that this
    article is amazing, nice written and come with almost all important infos.

    I would like to look extra posts like this .

    Balas
  31. Deadlift Shoes Official Website says:
    2 tahun yang lalu

    Hi there, just became alert to your blog through Google, and found that it’s
    really informative. I’m gonna watch out for brussels.
    I’ll appreciate if you continue this in future.
    Many people will be benefited from your writing. Cheers!

    Balas
  32. sv 388 says:
    2 tahun yang lalu

    I every time emailed this blog post page to all my associates, because
    if like to read it next my contacts will too.

    Balas
  33. sv 388 says:
    2 tahun yang lalu

    Hello! I simply would like to offer you a big thumbs up for the
    excellent information you have got here on this post.
    I’ll be coming back to your web site for more soon.

    Balas
  34. sbobet says:
    2 tahun yang lalu

    It’s actually very difficult in this busy life to listen news on Television, thus I
    only use internet for that purpose, and take the latest news.

    Balas
  35. s 128 says:
    2 tahun yang lalu

    Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something.

    I think that you could do with a few pics to drive the message home a
    little bit, but instead of that, this is wonderful blog.
    A fantastic read. I will definitely be back.

    Balas
  36. vivo slot says:
    2 tahun yang lalu

    Wow, this piece of writing is pleasant, my younger sister is analyzing these things,
    therefore I am going to convey her.

    Balas
  37. Rosaria says:
    2 tahun yang lalu

    Wood household furniture has one thing really natural about it.
    There is this feeling of coziness, of attributes and also of elegance that
    may be be located in hardwood household furniture.

    Hardwood is actually born coming from the earth.
    It feeds the fire, breaks down in to ashes and also blows away.

    It is quite close to the human life in the world. Might be
    that is actually why it sounds so much with us. Might be actually that is actually why you still obtain that hot feeling when you
    touch a rich mahogany desk.

    Balas
  38. s 128 says:
    2 tahun yang lalu

    I couldn’t resist commenting. Very well written!

    Balas
  39. idnpoker says:
    2 tahun yang lalu

    Oh my goodness! Incredible article dude! Thanks, However I
    am going through problems with your RSS. I don’t know the reason why I am unable to subscribe to it.
    Is there anybody else having the same RSS problems?
    Anyone who knows the solution will you kindly respond? Thanks!!

    Balas
  40. attorney hail damage says:
    2 tahun yang lalu

    You really make it seem really easy together with your presentation but I find
    this topic to be actually something that
    I think I would never understand. It seems too complex and very broad for me.
    I’m having a look ahead for your subsequent put up,
    I will attempt to get the dangle of it!

    Also visit my website :: attorney hail damage

    Balas
  41. School Girl Shoes For Sale says:
    2 tahun yang lalu

    Hello Dear, are you truly visiting this site daily, if so after that
    you will without doubt obtain pleasant knowledge.

    Balas
  42. Outdoor Electrical Outlet Store says:
    2 tahun yang lalu

    Very great post. I simply stumbled upon your weblog and wanted
    to say that I have truly loved surfing around your blog
    posts. After all I’ll be subscribing to your feed and I hope you write again very soon!

    Balas
  43. arena powerskin says:
    2 tahun yang lalu

    Excellent blog here! Also your website loads
    up fast! What web host are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as fast as yours lol

    Balas
  44. inno stage fire pit says:
    2 tahun yang lalu

    Greetings! Very useful advice in this particular
    post! It is the little changes that make the largest changes.

    Thanks for sharing!

    Balas
  45. Yankee Candle Outlet Clearance says:
    2 tahun yang lalu

    For newest news you have to visit internet and on internet I found this web page as a best website for hottest
    updates.

    Balas
  46. mini fire pit says:
    2 tahun yang lalu

    Amazing blog! Is your theme custom made or did you download it
    from somewhere? A theme like yours with a few
    simple tweeks would really make my blog shine. Please let me know
    where you got your design. Kudos

    Balas
  47. 먹튀검증 추천 says:
    2 tahun yang lalu

    Hello there! Do you use Twitter? I’d like to follow you if that would be okay.
    I’m definitely enjoying your blog and look forward to new posts.

    Balas
  48. 먹튀검증 안내 says:
    2 tahun yang lalu

    bookmarked!!, I like your blog!

    Balas
  49. neomycin for dogs says:
    2 tahun yang lalu

    I think this is one of the so much significant info
    for me. And i am satisfied reading your article. However want to statement on few common issues,
    The web site taste is ideal, the articles is actually
    nice : D. Just right activity, cheers

    Balas
  50. vivo slot says:
    2 tahun yang lalu

    Having read this I believed it was very informative.
    I appreciate you finding the time and energy to put
    this informative article together. I once again find myself spending a significant amount of
    time both reading and leaving comments. But so what, it was still worthwhile!

    Balas

Tinggalkan Balasan Batalkan balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Blog Firman Santosa

Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.

Subscribe Our Newsletter

[mc4wp_form]

© 2019 JNews - Premium WordPress news & magazine theme by Jegtheme.

Tidak ada hasil
Tampilkan semua hasil
  • Buy JNews
  • Homepage
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In