Output to Console in Bnlang
In Bnlang, the console is the primary way to display information while running a program.
The built‑in console
object provides multiple methods to print messages, debug, or log errors.
Basic Methods
console.log()
→ Print general messages.console.info()
→ Print informational messages.console.warn()
→ Print warning messages.console.error()
→ Print error messages.
Examples
console.log("Hello, World!");
console.info("Server started");
console.warn("Low memory");
console.error("Something went wrong");
Formatting Output
console.log
supports format specifiers like %s
(string), %d
(number), and %o
(object).
const user = "Alice";
const age = 25;
console.log("User: %s, Age: %d", user, age);
Best Practices
- Use
console.log
for development but clean up logs in production. - Use appropriate log levels (
info
,warn
,error
) for clarity. - Avoid logging sensitive information.
- Combine logs with monitoring tools for larger projects.