Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Programming Fundamentals/Introduction Examples JavaScript

From Wikibooks, open books for an open world
<Programming Fundamentals
Thelatest reviewed version waschecked on3 November 2022. There aretemplate/file changes awaiting review.

Overview

[edit |edit source]

JavaScript, often abbreviated as JS, is a high-level, interpreted programming language. Alongside HTML and CSS, JavaScript is one of the three core technologies of the World Wide Web. JavaScript enables interactive web pages and therefore is an essential part of web applications. The vast majority of websites use it, and all major web browsers have a dedicated JavaScript engine to execute it.[1]

JavaScript is one of the most popular current programming languages[2], and is the primary programming language for front-end web development. JavaScript files have a .js file extension. JavaScript has been implemented in multiple platforms with different I/O commands. Several examples follow.

Example

[edit |edit source]

Hello World – Console Log

[edit |edit source]
// This script displays "Hello world!".//// References:// https://www.digitalocean.com/community/tutorials/how-to-write-your-first-javascript-programconsole.log("Hello world!")

Output

[edit |edit source]
Hello world!

Discussion

[edit |edit source]

Each code element represents:

  • // begins a comment
  • console.log() writes to the JavaScript console output log
  • "Hello world!" is the literal string to be displayed

Hello World – Window Alert

[edit |edit source]
// This script displays "Hello world!".//// References:// https://www.digitalocean.com/community/tutorials/how-to-write-your-first-javascript-programalert("Hello world!")

Output

[edit |edit source]
Hello world!

Discussion

[edit |edit source]

Each code element represents:

  • // begins a comment
  • alert() calls the window alert function to display a message
  • "Hello world!" is the literal string to be displayed

Hello World – Document Write

[edit |edit source]
// This script displays "Hello world!".//// References:// https://www.w3schools.com/jsref/met_doc_write.aspdocument.write("Hello world!")

Output

[edit |edit source]
Hello world!

Discussion

[edit |edit source]

Each code element represents:

  • // begins a comment
  • document.write() writes output to the current document
  • "Hello world!" is the literal string to be displayed

JavaScript IDEs

[edit |edit source]

There are many free cloud-based and local IDEs available to begin coding in JavaScript. Check with your instructor or do your own research for recommendations.

Cloud-Based IDEs

[edit |edit source]

Local IDEs

[edit |edit source]

References

[edit |edit source]
  1. Wikipedia: JavaScript
  2. TIOBE: Index
← Introduction Examples Java
Programming Fundamentals
Introduction Examples Python →
Retrieved from "https://en.wikibooks.org/w/index.php?title=Programming_Fundamentals/Introduction_Examples_JavaScript&oldid=4199074"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp