Skip to content

Try our new Crash Courses!

Become a member using the button below to hide this banner and gain access to our new Crash Courses.

Inline script – JavaScript

Summary

To create an inline script, place your JavaScript code directly inside a script element:

<script>
  console.log("Test message");
</script>

Details

When writing JavaScript, you have the option of placing JavaScript code directly inside a script element in an HTML file. Please note, however, that this is generally not recommended. Inline scripts are acceptable for quick testing of JavaScript code, but the best practice is to store your JavaScript code in a separate JavaScript file.

Note that you do not need the src attribute when creating an inline script.

Demo

inline script demo

Exercises

Try recreating the code snippet from the lesson in the index.html file.

References

The Script element on MDN

Back to: JavaScript Reference > JS Introduction